ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BHepRepWriter.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BHepRepWriter.h
1 // Copyright FreeHEP, 2005.
2 #ifndef CHEPREP_BHEPREPWRITER_H
3 #define CHEPREP_BHEPREPWRITER_H
4 
5 #include "cheprep/config.h"
6 
7 #include <string>
8 #include <iostream>
9 #include <vector>
10 #include <map>
11 
13 
17 namespace cheprep {
18 
20 
21  public:
22 
23  BHepRepWriter(std::ostream& os);
24  virtual ~BHepRepWriter();
25 
26  void close();
27  void openDoc(std::string version = "BinaryHepRep/1.0", std::string encoding = "UTF-8", bool standalone = false);
28  void closeDoc(bool force = false);
29  void openTag(std::string name);
30  void closeTag();
31  void printTag(std::string name);
32  void setAttribute(std::string name, char* value);
33  void setAttribute(std::string name, std::string value);
34  void setAttribute(std::string name, std::vector<double> value);
35  void setAttribute(std::string name, int64 value);
36  void setAttribute(std::string name, int value);
37  void setAttribute(std::string name, bool value);
38  void setAttribute(std::string name, double value);
39 
40  //
41  // Can be removed when we can properly inherit those (since names are equal to overloaded ones).
42  //
43  void openTag(std::string ns, std::string name) {
44  openTag(ns == defaultNameSpace ? name : ns.append(":").append(name));
45  }
46  void printTag(std::string ns, std::string name) {
47  printTag(ns == defaultNameSpace ? name : ns.append(":").append(name));
48  }
49  void setAttribute(std::string ns, std::string name, std::string value) {
50  setAttribute(ns.append(":").append(name), value);
51  }
52  void setAttribute(std::string ns, std::string name, double value) {
53  setAttribute(ns.append(":").append(name), value);
54  }
55 
56  private:
57  static const unsigned char WBXML_VERSION = 0x03;
58  static const unsigned char UNKNOWN_PID = 0x01;
59  static const unsigned char UTF8 = 0x6a;
60 
61  // standard tags
62  static const unsigned char SWITCH_PAGE = 0x00;
63  static const unsigned char END = 0x01;
64  static const unsigned char ENTITY = 0x02;
65  static const unsigned char STR_I = 0x03;
66  static const unsigned char LITERAL = 0x04;
67 
68  static const unsigned char CONTENT = 0x40;
69  static const unsigned char EXT_I_0 = 0x40;
70  static const unsigned char EXT_I_1 = 0x41;
71  static const unsigned char EXT_I_2 = 0x42;
72  static const unsigned char PI = 0x43;
73  static const unsigned char LITERAL_C = 0x44;
74 
75  static const unsigned char ATTRIBUTE = 0x80;
76  static const unsigned char EXT_T_0 = 0x80;
77  static const unsigned char EXT_T_1 = 0x81;
78  static const unsigned char EXT_T_2 = 0x82;
79  static const unsigned char STR_T = 0x83;
80  static const unsigned char LITERAL_A = 0x84;
81 
82  static const unsigned char EXT_0 = 0xC0;
83  static const unsigned char EXT_1 = 0xC1;
84  static const unsigned char EXT_2 = 0xC2;
85  static const unsigned char OPAQUE = 0xC3;
86  static const unsigned char LITERAL_AC = 0xC4;
87 
88  // our own extensions
89  static const unsigned char STR_D = EXT_I_0;
90  static const unsigned char STR_R = EXT_T_0;
91 
92  // class definitions
93  static std::map<std::string, unsigned char> tags;
94  static std::map<std::string, unsigned char> attributes;
95  static std::map<std::string, unsigned char> values;
96 
97  // outputstream variables
98  std::ostream& os;
101 
102  // document variables
103  std::map<std::string, unsigned int> stringValues;
104 
105  // tag variables
106  std::map<std::string, std::string> stringAttributes;
107  std::map<std::string, std::vector<double> > colorAttributes;
108  std::map<std::string, int64> longAttributes;
109  std::map<std::string, int> intAttributes;
110  std::map<std::string, bool> booleanAttributes;
111  std::map<std::string, double> doubleAttributes;
112 
113  // point array
114  std::vector<double> points;
115 
116  // methods
117  void writeTag(std::string name, bool content = false);
118  void writePoints();
119  void writeStringDefine(std::string s);
120  void writeMultiByteInt(unsigned int ui);
121  void writeReal(double ui);
122  void writeLong(int64 i);
123  void writeInt(int i);
124  void writeByte(unsigned char b);
125  void writeString(std::string s);
126  };
127 
128 } // cheprep
129 
130 #endif // CHEPREP_BHEPREPWRITER_H