util/qos/HistoryQos.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      HistoryQos.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #include <util/qos/HistoryQos.h>
00008 #include <util/Global.h>
00009 #include <util/lexical_cast.h>
00010 
00011 
00012 using namespace std;
00013 using namespace org::xmlBlaster::util;
00014 
00015 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00016 
00017 const long DEFAULT_numEntries = 1;
00018 const bool DEFAULT_newestFirst = true;
00019 
00020 HistoryQos::HistoryQos(Global& global, long numOfEntries) 
00021    : ME("HistoryQos"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), newestFirst_(DEFAULT_newestFirst)
00022 {
00023    if (numOfEntries < 0)
00024         setNumEntries(global_.getProperty().getLongProperty("history.numEntries", DEFAULT_numEntries));
00025    else setNumEntries(numOfEntries);
00026 }
00027 
00028 HistoryQos::HistoryQos(const HistoryQos& qos)
00029    : ME(qos.ME), global_(qos.global_), log_(qos.log_)
00030 {
00031    numEntries_ = qos.numEntries_;
00032    newestFirst_ = qos.newestFirst_;
00033 }
00034 
00035 HistoryQos& HistoryQos::operator =(const HistoryQos& qos)
00036 {
00037    if (this == &qos)
00038       return *this;
00039    numEntries_ = qos.numEntries_;
00040    newestFirst_ = qos.newestFirst_;
00041    return *this;
00042 }
00043 
00044 void HistoryQos::setNumEntries(long numOfEntries)
00045 {
00046    if (numOfEntries < 0) numEntries_ = -1;
00047    else numEntries_ = numOfEntries;
00048 }
00049 
00050 long HistoryQos::getNumEntries() const
00051 {
00052    return numEntries_;
00053 }
00054 
00055 void HistoryQos::setNewestFirst(bool newestFirst)
00056 {
00057    newestFirst_ = newestFirst;
00058 }
00059 
00060 bool HistoryQos::getNewestFirst() const
00061 {
00062    return newestFirst_;
00063 }
00064 
00065 string HistoryQos::toXml(const string& extraOffset) const
00066 {
00067    if (getNumEntries() == DEFAULT_numEntries &&
00068        getNewestFirst() == DEFAULT_newestFirst) {
00069       return "";
00070    }
00071    string ret;
00072    string offset = "\n " + extraOffset;
00073    ret += offset + "<history numEntries='" +
00074                    lexical_cast<std::string>(getNumEntries()) +
00075                    "' newestFirst='" +
00076                    lexical_cast<std::string>(getNewestFirst()) +
00077                    "'/>";
00078    return ret;
00079 }
00080 
00081 }}}} //namespace
00082 
00083