19 #ifndef _PERSISTED_QUEUE_HPP_
20 #define _PERSISTED_QUEUE_HPP_
30 #include <boost/noncopyable.hpp>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/regex.hpp>
33 #include <boost/archive/iterators/base64_from_binary.hpp>
34 #include <boost/archive/iterators/binary_from_base64.hpp>
35 #include <boost/archive/iterators/transform_width.hpp>
36 #include <boost/archive/iterators/remove_whitespace.hpp>
37 #include <boost/filesystem/operations.hpp>
38 #include <boost/filesystem/path.hpp>
39 #include <boost/filesystem/exception.hpp>
44 using namespace boost::archive::iterators;
54 typedef transform_width< binary_from_base64<remove_whitespace<std::string::const_iterator> > , 8, 6 >
BinaryType;
55 typedef base64_from_binary<transform_width<std::string::const_iterator,6,8> >
Base64Type;
60 virtual boost::shared_ptr<std::string> encode(
const boost::shared_ptr<T> obj2encode) = 0;
61 virtual boost::shared_ptr<T> decode(
const std::string& str2decode) = 0;
64 boost::shared_ptr<std::string> encodeToBase64String(
const std::string& s)
67 unsigned int writePaddChars = (3 - s.length() % 3) % 3;
68 boost::shared_ptr<std::string> base64;
70 base64.reset(
new std::string(Base64Type(s.begin()),Base64Type(s.end())));
72 base64->append(writePaddChars,
'=');
80 unsigned int paddChars = count(s.begin(), s.end(),
'=');
82 boost::shared_ptr<std::string> result;
86 if(is[is.size()-1] ==
'=') is[is.size()-1] =
'A';
87 if(is[is.size()-2] ==
'=') is[is.size()-2] =
'A';
91 result->erase(result->end()-paddChars,result->end());
106 #define QueuedObjectPointerType boost::shared_ptr<_qoT >
107 #define QueueType std::deque<QueuedObjectPointerType >
108 #define QueueTypePtr boost::shared_ptr<QueueType >
109 #define QueueTypeIterator typename std::deque<boost::shared_ptr<_qoT > >::iterator
110 #define value_type QueueType::value_type
113 template <
class _qoT,
class _sT>
118 const std::string& queueWorkingDir,
119 const unsigned maxItemsPerPage);
135 void setWorkingDirectory (std::string wdir);
137 QueueTypePtr loadFromFile (
const std::string& path2File);
139 void loadFirstAndLastPage ();
140 void loadPersistedFileNames();
141 void loadOrphanedQueueFiles();
142 void makeStateFilePath ();
143 bool stateFileExists ();
144 void loadStateFile ();
145 void writeFirstAndLastPage ();
146 void writeStateFile ();
147 std::string seqNumber ();
149 std::string _queueName;
150 boost::filesystem::path _workingDirectory;
151 boost::filesystem::path _stateFilePath;
152 unsigned _maxItemsPerPage;
153 boost::regex _queueFileRegex;
155 std::deque<std::string> persistedFileNames;
164 #include "persisted_queue.tpp"
Definition: persisted_queue.hpp:114
Base64BiCoder()
Definition: persisted_queue.hpp:57
Definition: persisted_queue.hpp:51
transform_width< binary_from_base64< remove_whitespace< std::string::const_iterator > >, 8, 6 > BinaryType
Definition: persisted_queue.hpp:54
#define QueuedObjectPointerType
Definition: persisted_queue.hpp:106
bool empty()
Definition: persisted_queue.hpp:128
base64_from_binary< transform_width< std::string::const_iterator, 6, 8 > > Base64Type
Definition: persisted_queue.hpp:55
~Base64BiCoder()
Definition: persisted_queue.hpp:58
LogStream & debug_normal(LogStream &s, const bool permanent=false)
Definition: logstream.hpp:353
Definition: logstream.hpp:145
boost::shared_ptr< std::string > decodeFromBase64(const std::string &s)
Definition: persisted_queue.hpp:77
#define QueueTypePtr
Definition: persisted_queue.hpp:108
LogStream & endl(LogStream &s)
Definition: logstream.hpp:328