BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/AsciiDmp/include/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 <iostream>
6#include <string>
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 ){};
20
21public:
22 std::string expected() const { return m_expected; }
23 std::string got() const { return m_got; };
24
25private:
26 std::string m_expected;
27 std::string m_got;
28};
29
31public:
32 AsciiWrongStartTag( const std::string& expected, const std::string& got )
34};
35
37public:
38 AsciiWrongEndTag( const std::string& expected, const std::string& got )
40};
41
42//
43// the base class of all tagged classes
44//
45class Tagged {
46public:
47 Tagged() : m_initialized( false ){};
48
49public:
50 bool initialized() const;
51 void set_initialized();
52 void unset_initalized();
53
54protected:
55 void check_start_tag( std::istream& is, const char* tag );
56 void check_end_tag( std::istream& is, const char* tag );
57
58private:
59 bool m_initialized;
60 static std::string s_saved_tag;
61};
62
63inline bool Tagged::initialized() const { return m_initialized; }
64
65inline void Tagged::set_initialized() { m_initialized = true; }
66
67inline void Tagged::unset_initalized() { m_initialized = false; }
68
69inline void Tagged::check_start_tag( std::istream& is, const char* tag ) {
70 // read input, check for '{' character
71 char c;
72 if ( !( is >> c ) || ( c != '{' ) ) { throw AsciiNoStartChar(); }
73
74 // compare tags
75 std::string in_tag;
76 is >> in_tag;
77 if ( in_tag != tag ) throw AsciiWrongStartTag( tag, in_tag );
78
79 // check for empty block
80 is >> c;
81 if ( c == '}' )
82 {
83 is >> in_tag;
84 if ( in_tag != tag ) throw AsciiWrongEndTag( tag, in_tag );
85 }
86 else
87 {
88 is.putback( c );
90 }
91}
92
93inline void Tagged::check_end_tag( std::istream& is, const char* tag ) {
94 char c;
95 is >> c;
96 if ( c != '}' ) throw AsciiNoEndChar();
97
98 std::string in_tag;
99 is >> in_tag;
100 if ( in_tag != tag ) throw AsciiWrongEndTag( tag, in_tag );
101}
102
103#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)