EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RowsetReader.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #ifndef __ROWSETREADER_H_INCL__
27 #define __ROWSETREADER_H_INCL__
28 
29 #include "packets/General.h"
30 #include "python/PyVisitor.h"
31 
33 {
34 public:
35  virtual ~BaseRowsetReader() {}
36 
37  /* Required set of operations:
38  iterator begin();
39  iterator end();
40  */
41 
42  virtual size_t columnCount() const = 0;
43  virtual const char* columnName( size_t index ) const = 0;
44  virtual size_t FindColumn( const char* name );
45 
46  virtual size_t rowCount() const = 0;
47 
48 protected:
49  class iterator
50  {
51  public:
52  virtual PyRep::PyType GetType( size_t index ) const = 0;
53  virtual bool IsNone( size_t index ) const { return ( PyRep::PyTypeNone == GetType( index ) ); }
54 
55  virtual bool GetBool( size_t index ) const = 0;
56  virtual uint32 GetInt( size_t index ) const = 0;
57  virtual int64 GetLong( size_t index ) const = 0;
58  virtual double GetFloat( size_t index ) const = 0;
59  virtual const char* GetString( size_t index ) const = 0;
60  virtual const char* GetWString( size_t index ) const = 0;
61 
62  //convert whatever we have into a string
63  std::string GetAsString( size_t index ) const;
64 
65  const iterator& operator++();
66  const iterator& operator++(int) { return ++*this; }
67  const iterator& operator--();
68  const iterator& operator--(int) { return --*this; }
69 
70  bool operator==( const iterator& oth ) const;
71  bool operator!=( const iterator& oth ) const { return !( *this == oth ); }
72 
73  protected:
74  iterator();
75 
76  virtual size_t _rowIndex() const { return mRowIndex; }
77  virtual BaseRowsetReader* _baseReader() const = 0;
78 
79  virtual void _SetRow( size_t rowIndex ) { mRowIndex = rowIndex; }
80 
81  size_t mRowIndex;
82  };
83 };
84 
86 {
87 protected:
89  {
90  public:
91  virtual PyRep* GetRep( size_t index ) const = 0;
92 
93  PyRep::PyType GetType( size_t index ) const { return GetRep( index )->GetType(); }
94  bool IsNone( size_t index ) const;
95 
96  bool GetBool( size_t index ) const;
97  uint32 GetInt( size_t index ) const;
98  int64 GetLong( size_t index ) const;
99  double GetFloat( size_t index ) const;
100  const char* GetString( size_t index ) const;
101  const char* GetWString( size_t index ) const;
102  };
103 };
104 
106 {
107 public:
108  RowsetReader( const util_Rowset& rowset );
109  ~RowsetReader();
110 
112  {
113  friend class RowsetReader;
114  public:
115  iterator();
116 
117  PyRep* GetRep( size_t index ) const { return mRow->GetItem( index ); }
118 
119  protected:
120  iterator( RowsetReader* parent, size_t rowIndex );
121 
122  BaseRowsetReader* _baseReader() const { return mParent; }
123 
124  void _SetRow( size_t rowIndex );
125 
128  };
129 
130  size_t columnCount() const { return mSet.header.size(); }
131  const char* columnName( size_t index ) const { return mSet.header[ index ].c_str(); }
132 
133  size_t rowCount() const { return mSet.lines->size(); }
134 
135  iterator begin() { return iterator( this, 0 ); }
136  iterator end() { return iterator( this, rowCount() ); }
137 
138 protected:
139  PyList* _GetRow( size_t index ) const { return mSet.lines->GetItem( index )->AsList(); }
140 
141  const util_Rowset& mSet;
142 };
143 
145 {
146 public:
147  TuplesetReader( const util_Tupleset& tupleset );
148 
150  {
151  friend class TuplesetReader;
152  public:
153  iterator();
154 
155  PyRep* GetRep( size_t index ) const { return mRow->GetItem( index ); }
156 
157  protected:
158  iterator( TuplesetReader* parent, size_t rowIndex );
159 
160  BaseRowsetReader* _baseReader() const { return mParent; }
161 
162  void _SetRow( size_t rowIndex );
163 
166  };
167 
168  size_t columnCount() const { return mSet.header.size(); }
169  const char* columnName( size_t index ) const { return mSet.header[ index ].c_str(); }
170 
171  size_t rowCount() const { return mSet.lines->size(); }
172 
173  iterator begin() { return iterator( this, 0 ); }
174  iterator end() { return iterator( this, rowCount() ); }
175 
176 protected:
177  PyList* _GetRow( size_t index ) const { return mSet.lines->GetItem( index )->AsList(); }
178 
179  const util_Tupleset& mSet; //we do NOT own this pointer
180 };
181 
192 : public PyVisitor
193 {
194 public:
195  SetSQLDumper( const char* table, const char* keyField, FILE* out );
196 
197  bool VisitTuple( const PyTuple* rep );
198 
199  bool VisitObject( const PyObject* rep );
200 
201 protected:
202  const std::string mTable;
203  const std::string mKeyField;
204  FILE* const mOut;
205 };
206 
207 #endif
208 
209 
Base Python wire object.
Definition: PyRep.h:66
bool operator!=(const iterator &oth) const
Definition: RowsetReader.h:71
std::string GetAsString(size_t index) const
virtual size_t columnCount() const =0
const util_Tupleset & mSet
Definition: RowsetReader.h:179
size_t rowCount() const
Definition: RowsetReader.h:171
virtual const char * columnName(size_t index) const =0
virtual size_t rowCount() const =0
TuplesetReader * mParent
Definition: RowsetReader.h:164
PyRep::PyType GetType(size_t index) const
Definition: RowsetReader.h:93
const iterator & operator++()
virtual int64 GetLong(size_t index) const =0
size_t rowCount() const
Definition: RowsetReader.h:133
virtual PyRep * GetRep(size_t index) const =0
bool operator==(const iterator &oth) const
virtual BaseRowsetReader * _baseReader() const =0
virtual ~BaseRowsetReader()
Definition: RowsetReader.h:35
const std::string mKeyField
Definition: RowsetReader.h:203
Python object SQL dumper.
Definition: RowsetReader.h:191
SetSQLDumper(const char *table, const char *keyField, FILE *out)
BaseRowsetReader * _baseReader() const
Definition: RowsetReader.h:122
uint32 GetInt(size_t index) const
PyRep * GetRep(size_t index) const
Definition: RowsetReader.h:117
virtual void _SetRow(size_t rowIndex)
Definition: RowsetReader.h:79
const char * columnName(size_t index) const
Definition: RowsetReader.h:169
void _SetRow(size_t rowIndex)
Python tuple.
Definition: PyRep.h:567
PyType GetType() const
Definition: PyRep.h:98
const char * columnName(size_t index) const
Definition: RowsetReader.h:131
virtual const char * GetString(size_t index) const =0
virtual bool GetBool(size_t index) const =0
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:674
const iterator & operator--()
const iterator & operator++(int)
Definition: RowsetReader.h:66
iterator end()
Definition: RowsetReader.h:136
TuplesetReader(const util_Tupleset &tupleset)
iterator begin()
Definition: RowsetReader.h:135
Python object.
Definition: PyRep.h:826
const util_Rowset & mSet
Definition: RowsetReader.h:141
virtual PyRep::PyType GetType(size_t index) const =0
bool VisitObject(const PyObject *rep)
Object type visitor.
virtual size_t FindColumn(const char *name)
iterator end()
Definition: RowsetReader.h:174
int64 GetLong(size_t index) const
bool GetBool(size_t index) const
RowsetReader * mParent
Definition: RowsetReader.h:126
virtual size_t _rowIndex() const
Definition: RowsetReader.h:76
bool IsNone(size_t index) const
void _SetRow(size_t rowIndex)
unsigned __int32 uint32
Definition: eve-compat.h:50
PyType
Python wire object types.
Definition: PyRep.h:72
virtual double GetFloat(size_t index) const =0
const iterator & operator--(int)
Definition: RowsetReader.h:68
size_t columnCount() const
Definition: RowsetReader.h:168
const char * GetString(size_t index) const
signed __int64 int64
Definition: eve-compat.h:51
size_t columnCount() const
Definition: RowsetReader.h:130
iterator begin()
Definition: RowsetReader.h:173
const char * GetWString(size_t index) const
virtual const char * GetWString(size_t index) const =0
FILE *const mOut
Definition: RowsetReader.h:204
bool VisitTuple(const PyTuple *rep)
the nested types Visitor
double GetFloat(size_t index) const
virtual uint32 GetInt(size_t index) const =0
PyList * _GetRow(size_t index) const
Definition: RowsetReader.h:139
PyRep * GetRep(size_t index) const
Definition: RowsetReader.h:155
const std::string mTable
Definition: RowsetReader.h:202
PyList * _GetRow(size_t index) const
Definition: RowsetReader.h:177
virtual bool IsNone(size_t index) const
Definition: RowsetReader.h:53
BaseRowsetReader * _baseReader() const
Definition: RowsetReader.h:160
Python list.
Definition: PyRep.h:639
RowsetReader(const util_Rowset &rowset)