CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/AsciiDmp/AsciiDmp-01-04-03/AsciiDmp/dmplib.hh
Go to the documentation of this file.
1/* this is -*- C++ -*- */
2#ifndef SPEC_DMPLIB_H_
3#define SPEC_DMPLIB_H_
4
5#include <string>
6#include <iostream>
7
8//
9// exceptions raised
10//
12
15
17public:
18 AsciiWrongTag(const std::string& expected, const std::string& got)
19 : m_expected(expected), m_got(got) {};
20public:
21 std::string expected() const { return m_expected; }
22 std::string got() const { return m_got; };
23private:
24 std::string m_expected;
25 std::string m_got;
26};
27
29public:
30 AsciiWrongStartTag(const std::string& expected, const std::string& got)
32 {}
33};
34
36public:
37 AsciiWrongEndTag(const std::string& expected, const std::string& got)
39 {}
40};
41
42//
43// the base class of all tagged classes
44//
45class Tagged {
46public:
48 : m_initialized(false)
49 {};
50public:
51 bool initialized() const;
52 void set_initialized();
53 void unset_initalized();
54protected:
55 void check_start_tag(std::istream& is, const char *tag);
56 void check_end_tag(std::istream& is, const char *tag);
57private:
58 bool m_initialized;
59 static std::string s_saved_tag;
60};
61
62inline
64{
65 return m_initialized;
66}
67
68inline
70{
71 m_initialized = true;
72}
73
74inline
76{
77 m_initialized = false;
78}
79
80inline
81void Tagged::check_start_tag(std::istream& is, const char *tag)
82{
83 // read input, check for '{' character
84 char c;
85 if(!(is >> c) || (c != '{')) {
86 throw AsciiNoStartChar();
87 }
88
89 // compare tags
90 std::string in_tag;
91 is >> in_tag;
92 if(in_tag != tag)
93 throw AsciiWrongStartTag(tag, in_tag);
94
95 // check for empty block
96 is >> c;
97 if(c == '}') {
98 is >> in_tag;
99 if(in_tag != tag)
100 throw AsciiWrongEndTag(tag, in_tag);
101 } else {
102 is.putback(c);
104 }
105}
106
107inline
108void Tagged::check_end_tag(std::istream& is, const char *tag)
109{
110 char c;
111 is >> c;
112 if(c != '}')
113 throw AsciiNoEndChar();
114
115 std::string in_tag;
116 is >> in_tag;
117 if(in_tag != tag)
118 throw AsciiWrongEndTag(tag, in_tag);
119}
120
121
122#endif /* SPEC_DMPLIB_H_ */
AsciiWrongEndTag(const std::string &expected, const std::string &got)
AsciiWrongStartTag(const std::string &expected, const std::string &got)
AsciiWrongTag(const std::string &expected, const std::string &got)
void check_start_tag(std::istream &is, const char *tag)
void check_end_tag(std::istream &is, const char *tag)