1 /*------------------------------------------------------------------------------
2 Name: HistoryQos.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 #include <util/qos/HistoryQos.h>
8 #include <util/Global.h>
9 #include <util/lexical_cast.h>
10
11
12 using namespace std;
13 using namespace org::xmlBlaster::util;
14
15 namespace org { namespace xmlBlaster { namespace util { namespace qos {
16
17 const long DEFAULT_numEntries = 1;
18 const bool DEFAULT_newestFirst = true;
19
20 HistoryQos::HistoryQos(Global& global, long numOfEntries)
21 : ME("HistoryQos"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")), newestFirst_(DEFAULT_newestFirst)
22 {
23 if (numOfEntries < 0)
24 setNumEntries(global_.getProperty().getLongProperty("history.numEntries", DEFAULT_numEntries));
25 else setNumEntries(numOfEntries);
26 }
27
28 HistoryQos::HistoryQos(const HistoryQos& qos)
29 : ME(qos.ME), global_(qos.global_), log_(qos.log_)
30 {
31 numEntries_ = qos.numEntries_;
32 newestFirst_ = qos.newestFirst_;
33 }
34
35 HistoryQos& HistoryQos::operator =(const HistoryQos& qos)
36 {
37 if (this == &qos)
38 return *this;
39 numEntries_ = qos.numEntries_;
40 newestFirst_ = qos.newestFirst_;
41 return *this;
42 }
43
44 void HistoryQos::setNumEntries(long numOfEntries)
45 {
46 if (numOfEntries < 0) numEntries_ = -1;
47 else numEntries_ = numOfEntries;
48 }
49
50 long HistoryQos::getNumEntries() const
51 {
52 return numEntries_;
53 }
54
55 void HistoryQos::setNewestFirst(bool newestFirst)
56 {
57 newestFirst_ = newestFirst;
58 }
59
60 bool HistoryQos::getNewestFirst() const
61 {
62 return newestFirst_;
63 }
64
65 string HistoryQos::toXml(const string& extraOffset) const
66 {
67 if (getNumEntries() == DEFAULT_numEntries &&
68 getNewestFirst() == DEFAULT_newestFirst) {
69 return "";
70 }
71 string ret;
72 string offset = "\n " + extraOffset;
73 ret += offset + "<history numEntries='" +
74 lexical_cast<std::string>(getNumEntries()) +
75 "' newestFirst='" +
76 lexical_cast<std::string>(getNewestFirst()) +
77 "'/>";
78 return ret;
79 }
80
81 }}}} //namespace
syntax highlighted by Code2HTML, v. 0.9.1