source: trunk/source/visualization/HepRep/include/cheprep/BHepRepWriter.h @ 834

Last change on this file since 834 was 834, checked in by garnier, 16 years ago

import all except CVS

  • Property svn:executable set to *
File size: 5.5 KB
Line 
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
12#include "cheprep/AbstractXMLWriter.h"
13
14/**
15 * @author Mark Donszelmann
16 * @version $Id: BHepRepWriter.h,v 1.9 2005/06/02 21:28:45 duns Exp $
17 */
18namespace cheprep {
19
20    class BHepRepWriter : public AbstractXMLWriter {
21
22        public:
23
24            BHepRepWriter(std::ostream& os);
25            virtual ~BHepRepWriter();
26
27            void close();
28            void openDoc(std::string version = "BinaryHepRep/1.0", std::string encoding = "UTF-8", bool standalone = false);
29            void closeDoc(bool force = false);
30            void openTag(std::string name);
31            void closeTag();
32            void printTag(std::string name);
33            void setAttribute(std::string name, char* value);
34            void setAttribute(std::string name, std::string value);
35            void setAttribute(std::string name, std::vector<double> value);
36            void setAttribute(std::string name, int64 value);
37            void setAttribute(std::string name, int value);
38            void setAttribute(std::string name, bool value);
39            void setAttribute(std::string name, double value);
40
41            //
42            // Can be removed when we can properly inherit those (since names are equal to overloaded ones).
43            //
44            void openTag(std::string ns, std::string name) {
45                openTag(ns == defaultNameSpace ? name : ns.append(":").append(name));
46            }
47            void printTag(std::string ns, std::string name) {
48                printTag(ns == defaultNameSpace ? name : ns.append(":").append(name));
49            }
50            void setAttribute(std::string ns, std::string name, std::string value) {
51                setAttribute(ns.append(":").append(name), value);
52            }
53            void setAttribute(std::string ns, std::string name, double value) {
54                setAttribute(ns.append(":").append(name), value);
55            }
56
57        private:
58            static const unsigned char WBXML_VERSION    = 0x03;
59            static const unsigned char UNKNOWN_PID      = 0x01;
60            static const unsigned char UTF8             = 0x6a;
61       
62            // standard tags
63            static const unsigned char SWITCH_PAGE      = 0x00;
64            static const unsigned char END              = 0x01;
65            static const unsigned char ENTITY           = 0x02;
66            static const unsigned char STR_I            = 0x03;
67            static const unsigned char LITERAL          = 0x04;
68           
69            static const unsigned char CONTENT          = 0x40;
70            static const unsigned char EXT_I_0          = 0x40;
71            static const unsigned char EXT_I_1          = 0x41;
72            static const unsigned char EXT_I_2          = 0x42;
73            static const unsigned char PI               = 0x43;
74            static const unsigned char LITERAL_C        = 0x44;
75           
76            static const unsigned char ATTRIBUTE        = 0x80;
77            static const unsigned char EXT_T_0          = 0x80;
78            static const unsigned char EXT_T_1          = 0x81;
79            static const unsigned char EXT_T_2          = 0x82;
80            static const unsigned char STR_T            = 0x83;
81            static const unsigned char LITERAL_A        = 0x84;
82           
83            static const unsigned char EXT_0            = 0xC0;
84            static const unsigned char EXT_1            = 0xC1;
85            static const unsigned char EXT_2            = 0xC2;
86            static const unsigned char OPAQUE           = 0xC3;
87            static const unsigned char LITERAL_AC       = 0xC4;
88           
89            // our own extensions           
90            static const unsigned char STR_D            = EXT_I_0;
91            static const unsigned char STR_R            = EXT_T_0;
92           
93            // class definitions
94            static std::map<std::string, unsigned char> tags; 
95            static std::map<std::string, unsigned char> attributes;           
96            static std::map<std::string, unsigned char> values;
97
98            // outputstream variables
99            std::ostream& os;
100            bool singlePrecision;   
101            bool isBigEndian;
102           
103            // document variables           
104            std::map<std::string, unsigned int> stringValues;
105           
106            // tag variables
107            std::map<std::string, std::string> stringAttributes;
108            std::map<std::string, std::vector<double> > colorAttributes;
109            std::map<std::string, int64> longAttributes;
110            std::map<std::string, int> intAttributes;
111            std::map<std::string, bool> booleanAttributes;
112            std::map<std::string, double> doubleAttributes;
113           
114            // point array
115            std::vector<double> points;
116           
117            // methods
118            void writeTag(std::string name, bool content = false);
119            void writePoints();
120            void writeStringDefine(std::string s);                     
121            void writeMultiByteInt(unsigned int ui);                     
122            void writeReal(double ui);
123            void writeLong(int64 i);
124            void writeInt(int i);
125            void writeByte(unsigned char b);
126            void writeString(std::string s);
127    };
128 
129} // cheprep
130
131#endif // CHEPREP_BHEPREPWRITER_H
Note: See TracBrowser for help on using the repository browser.