Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mork / MorkParser.hxx
blobd0ecba7af9778be616307e7e9a9689a519a691f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Software License Agreement (BSD License)
5 * Copyright (c) 2006, ScalingWeb.com
6 * All rights reserved.
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:
11 * * Redistributions of source code must retain the above
12 * copyright notice, this list of conditions and the
13 * following disclaimer.
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.
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.
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.
35 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MORKPARSER_HXX
36 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MORKPARSER_HXX
38 #include <sal/types.h>
40 #include <string>
41 #include <map>
42 #include <set>
43 #include <vector>
45 #include "dllapi.h"
47 // Types
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
56 // Error codes
57 enum MorkErrors
59 NoError = 0,
60 FailedToOpen,
61 UnsupportedVersion,
62 DefectedFormat
65 // Mork term types
66 enum MorkTerm
68 NoneTerm = 0,
69 DictTerm,
70 GroupTerm,
71 TableTerm,
72 RowTerm,
73 CellTerm,
74 CommentTerm,
75 LiteralTerm
79 /// Class MorkParser
81 class LO_DLLPUBLIC_MORK MorkParser
83 public:
85 MorkParser( int defaultScope = 0x80 );
87 /// Open and parse mork file
89 bool open( const std::string &path );
91 /// Return error status
93 MorkErrors error();
95 /// Returns all tables of specified scope
97 MorkTableMap *getTables( int tableScope );
99 /// Rerturns all rows under specified scope
101 MorkRowMap *getRows( int rowScope, RowScopeMap *table );
103 /// Return value of specified value oid
105 std::string &getValue( int oid );
107 /// Return value of specified column oid
109 std::string &getColumn( int oid );
111 void retrieveLists(std::set<std::string>& lists);
112 void getRecordKeysForListTable(std::string& listName, std::set<int>& records);
114 void dump();
116 protected: // Members
118 void initVars();
120 bool isWhiteSpace( char c );
121 char nextChar();
123 void parseScopeId( const std::string &TextId, int *Id, int *Scope );
124 void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId );
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();
136 protected: // Data
138 // Columns in mork means value names
139 MorkDict columns_;
140 MorkDict values_;
142 // All mork file data
143 TableScopeMap mork_;
144 MorkCells *currentCells_;
146 // Error status of last operation
147 MorkErrors error_;
149 // All Mork data
150 std::string morkData_;
152 unsigned morkPos_;
153 int nextAddValueId_;
154 int defaultScope_;
155 int defaultListScope_;
156 int defaultTableId_;
158 // Indicates intity is being parsed
159 enum { NPColumns, NPValues, NPRows } nowParsing_;
161 private:
162 MorkParser(const MorkParser &);
163 MorkParser &operator=(const MorkParser &);
167 #endif // __MorkParser_h__
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */