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