Line data Source code
1 : #ifndef OKS_KERNEL_UTILS_H
2 : #define OKS_KERNEL_UTILS_H
3 :
4 : #include "oks/exceptions.hpp"
5 :
6 : #include <boost/date_time/posix_time/posix_time_types.hpp>
7 : #include <boost/date_time/gregorian/gregorian_types.hpp>
8 :
9 : #include <map>
10 : #include <string>
11 :
12 : namespace dunedaq {
13 : namespace oks {
14 :
15 : class OksClass;
16 : class OksObject;
17 : class OksXmlInputStream;
18 : class OksFile;
19 : struct OksAliasTable;
20 : class OksKernel;
21 :
22 : // read date and time strings from OKS files (oks::Date, oks::Time or Boost ISO strings)
23 :
24 : boost::posix_time::ptime str2time(const char * value, size_t len, const char * file_name = nullptr);
25 : boost::gregorian::date str2date(const char * value, size_t len);
26 :
27 :
28 : // the structure for efficient search of objects to be re-read or to be deleted during reload
29 :
30 : struct ReloadObjects {
31 :
32 :
33 : template<typename T>
34 : using map_str_t = std::map<std::string, T>;
35 :
36 : std::map< const OksClass *, map_str_t<OksObject *> * > data;
37 : std::vector<OksObject *> created;
38 :
39 : ~ReloadObjects();
40 : void put(OksObject * obj);
41 : OksObject * pop(const OksClass* c, const std::string& id);
42 : };
43 :
44 :
45 : // the structure to pass common parameters to various read() methods of OksData and OksObject class
46 :
47 : struct ReadFileParams {
48 : OksFile* f;
49 : OksXmlInputStream& s;
50 : OksAliasTable * alias_table;
51 : OksKernel * oks_kernel;
52 : char format;
53 : ReloadObjects * reload_objects;
54 : const char * object_tag;
55 : size_t object_tag_len;
56 : OksObject * owner;
57 : std::string tmp;
58 :
59 116 : ReadFileParams(OksFile* f_, OksXmlInputStream& s_, OksAliasTable * t_, OksKernel * k_, char m_, ReloadObjects * l_) :
60 116 : f(f_), s(s_), alias_table(t_), oks_kernel(k_), format(m_), reload_objects(l_) { init(); }
61 :
62 : void init();
63 : };
64 :
65 :
66 : // 17-SEP-2009: for compatibility with previous OKS versions
67 : // FIXME: remove later ...
68 :
69 : class Date {
70 :
71 : public:
72 :
73 0 : Date (const char * s) {set(s);} // dd/mm/[yy]yy
74 :
75 0 : virtual ~Date() { ; }
76 :
77 : void set(const char *);
78 :
79 0 : long year() const {return p_tm.tm_year;}
80 0 : unsigned short month() const {return p_tm.tm_mon;}
81 0 : unsigned short day() const {return p_tm.tm_mday;}
82 :
83 : virtual std::string str() const;
84 :
85 :
86 : protected:
87 :
88 : struct tm p_tm;
89 :
90 : };
91 :
92 : std::ostream& operator<<(std::ostream&, const Date&);
93 :
94 :
95 : class Time : public Date {
96 :
97 : public:
98 :
99 0 : Time (const char * s) : Date(s) {/*set(s);*/} // dd/mm/[yy]yy hh:mm[:ss]
100 :
101 0 : virtual ~Time() { ; }
102 :
103 0 : unsigned short hour() const {return p_tm.tm_hour;}
104 0 : unsigned short min() const {return p_tm.tm_min;}
105 0 : unsigned short sec() const {return p_tm.tm_sec;}
106 :
107 : virtual std::string str() const;
108 : };
109 :
110 : std::ostream& operator<<(std::ostream&, const Time&);
111 :
112 :
113 : } // namespace oks
114 : } // namespace dunedaq
115 :
116 : #endif
|