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 : #include <rtl/ustring.hxx>
40 :
41 : #include <string>
42 : #include <map>
43 : #include <set>
44 : #include <vector>
45 :
46 : #include "dllapi.h"
47 :
48 : // Types
49 :
50 : typedef std::map< int, std::string > MorkDict;
51 : typedef std::map< int, int > MorkCells; // ColumnId : ValueId
52 18 : struct MorkRowMap { typedef std::map< int, MorkCells > Map; Map map; }; // Row id
53 6 : struct RowScopeMap { typedef std::map< int, MorkRowMap > Map; Map map; }; // Row scope
54 6 : struct MorkTableMap { typedef std::map< int, RowScopeMap > Map; Map map; }; // Table id
55 12 : struct TableScopeMap { typedef std::map< int, MorkTableMap > Map; Map map; }; // Table Scope
56 :
57 : // Error codes
58 : enum MorkErrors
59 : {
60 : NoError = 0,
61 : FailedToOpen,
62 : UnsupportedVersion,
63 : DefectedFormat
64 : };
65 :
66 : // Mork term types
67 : enum MorkTerm
68 : {
69 : NoneTerm = 0,
70 : DictTerm,
71 : GroupTerm,
72 : TableTerm,
73 : RowTerm,
74 : CellTerm,
75 : CommentTerm,
76 : LiteralTerm
77 : };
78 :
79 :
80 : /// Class MorkParser
81 :
82 6 : class LO_DLLPUBLIC_MORK MorkParser
83 : {
84 : public:
85 :
86 : MorkParser( int defaultScope = 0x80 );
87 :
88 : /// Open and parse mork file
89 :
90 : bool open( const std::string &path );
91 :
92 : /// Return error status
93 :
94 : MorkErrors error();
95 :
96 : /// Returns all tables of specified scope
97 :
98 : MorkTableMap *getTables( int tableScope );
99 :
100 : /// Returns all rows under specified scope
101 :
102 : static MorkRowMap *getRows( int rowScope, RowScopeMap *table );
103 :
104 : /// Return value of specified value oid
105 :
106 : std::string &getValue( int oid );
107 :
108 : /// Return value of specified column oid
109 :
110 : std::string &getColumn( int oid );
111 :
112 : void retrieveLists(std::set<std::string>& lists);
113 : void getRecordKeysForListTable(std::string& listName, std::set<int>& records);
114 :
115 : void dump();
116 :
117 : // All lists
118 : std::vector<OUString> lists_;
119 :
120 : protected: // Members
121 :
122 : void initVars();
123 :
124 : static bool isWhiteSpace( char c );
125 : char nextChar();
126 :
127 : static void parseScopeId( const std::string &TextId, int *Id, int *Scope );
128 : void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId );
129 :
130 : // Parse methods
131 : bool parse();
132 : bool parseDict();
133 : bool parseComment();
134 : bool parseCell();
135 : bool parseTable();
136 : bool parseMeta( char c );
137 : bool parseRow( int TableId, int TableScope );
138 : bool parseGroup();
139 :
140 : protected: // Data
141 :
142 : // Columns in mork means value names
143 : MorkDict columns_;
144 : MorkDict values_;
145 :
146 : // All mork file data
147 : TableScopeMap mork_;
148 : MorkCells *currentCells_;
149 :
150 : // Error status of last operation
151 : MorkErrors error_;
152 :
153 : // All Mork data
154 : std::string morkData_;
155 :
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 &) SAL_DELETED_FUNCTION;
168 : MorkParser &operator=(const MorkParser &) SAL_DELETED_FUNCTION;
169 :
170 : };
171 :
172 : #endif // __MorkParser_h__
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|