Line data Source code
1 : /*
2 : * Software License Agreement (BSD License)
3 : *
4 : * Copyright (c) 2006, ScalingWeb.com
5 : * All rights reserved.
6 : *
7 : * Redistribution and use of this software in source and binary forms, with or without modification, are
8 : * permitted provided that the following conditions are met:
9 : *
10 : * * Redistributions of source code must retain the above
11 : * copyright notice, this list of conditions and the
12 : * following disclaimer.
13 : *
14 : * * Redistributions in binary form must reproduce the above
15 : * copyright notice, this list of conditions and the
16 : * following disclaimer in the documentation and/or other
17 : * materials provided with the distribution.
18 : *
19 : * * Neither the name of ScalingWeb.com nor the names of its
20 : * contributors may be used to endorse or promote products
21 : * derived from this software without specific prior
22 : * written permission of ScalingWeb.com.
23 :
24 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
25 : * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26 : * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
27 : * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 : * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 : * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 : * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 : */
33 :
34 : #ifndef _MORK_PARSER_HXX_
35 : #define _MORK_PARSER_HXX_
36 :
37 : #include <sal/types.h>
38 :
39 : #include <string>
40 : #include <map>
41 : #include <set>
42 : #include <vector>
43 :
44 : #include "dllapi.h"
45 :
46 : // Types
47 :
48 : typedef std::map< int, std::string > MorkDict;
49 : typedef std::map< int, int > MorkCells; // ColumnId : ValueId
50 : typedef std::map< int, MorkCells > MorkRowMap; // Row id
51 : typedef std::map< int, MorkRowMap > RowScopeMap; // Row scope
52 : typedef std::map< int, RowScopeMap > MorkTableMap; // Table id
53 : typedef std::map< int, MorkTableMap > TableScopeMap; // Table Scope
54 :
55 : // Error codes
56 : enum MorkErrors
57 : {
58 : NoError = 0,
59 : FailedToOpen,
60 : UnsupportedVersion,
61 : DefectedFormat
62 : };
63 :
64 : // Mork term types
65 : enum MorkTerm
66 : {
67 : NoneTerm = 0,
68 : DictTerm,
69 : GroupTerm,
70 : TableTerm,
71 : RowTerm,
72 : CellTerm,
73 : CommentTerm,
74 : LiteralTerm
75 : };
76 :
77 :
78 : /// Class MorkParser
79 :
80 1 : class LO_DLLPUBLIC_MORK MorkParser
81 : {
82 : public:
83 :
84 : MorkParser( int defaultScope = 0x80 );
85 :
86 : ///
87 : /// Open and parse mork file
88 :
89 : bool open( const std::string &path );
90 :
91 : ///
92 : /// Return error status
93 :
94 : MorkErrors error();
95 :
96 : ///
97 : /// Returns all tables of specified scope
98 :
99 : MorkTableMap *getTables( int tableScope );
100 :
101 : ///
102 : /// Rerturns all rows under specified scope
103 :
104 : MorkRowMap *getRows( int rowScope, RowScopeMap *table );
105 :
106 : ///
107 : /// Return value of specified value oid
108 :
109 : std::string &getValue( int oid );
110 :
111 : ///
112 : /// Return value of specified column oid
113 :
114 : std::string &getColumn( int oid );
115 :
116 : void retrieveLists(std::set<std::string>& lists);
117 : void getRecordKeysForListTable(std::string& listName, std::set<int>& records);
118 :
119 : void dump();
120 :
121 : protected: // Members
122 :
123 : void initVars();
124 :
125 : bool isWhiteSpace( char c );
126 : char nextChar();
127 :
128 : void parseScopeId( const std::string &TextId, int *Id, int *Scope );
129 : void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId );
130 :
131 : // Parse methods
132 : bool parse();
133 : bool parseDict();
134 : bool parseComment();
135 : bool parseCell();
136 : bool parseTable();
137 : bool parseMeta( char c );
138 : bool parseRow( int TableId, int TableScope );
139 : bool parseGroup();
140 :
141 : protected: // Data
142 :
143 : // Columns in mork means value names
144 : MorkDict columns_;
145 : MorkDict values_;
146 :
147 : // All mork file data
148 : TableScopeMap mork_;
149 : MorkCells *currentCells_;
150 :
151 : // Error status of last operation
152 : MorkErrors error_;
153 :
154 : // All Mork data
155 : std::string morkData_;
156 :
157 : unsigned morkPos_;
158 : int nextAddValueId_;
159 : int defaultScope_;
160 : int defaultListScope_;
161 : int defaultTableId_;
162 :
163 : // Indicates intity is being parsed
164 : enum { NPColumns, NPValues, NPRows } nowParsing_;
165 :
166 : private:
167 : MorkParser(const MorkParser &);
168 : MorkParser &operator=(const MorkParser &);
169 :
170 : };
171 :
172 : #endif // __MorkParser_h__
173 :
|