全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド ページ
fields.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_FIELDS_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_FIELDS_H
3 /*=================================================================
4  Copyright (C) 2014 BizStation Corp All rights reserved.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 =================================================================*/
21 #include "field.h"
22 #include "table.h"
23 #include <boost/shared_ptr.hpp>
24 #include <stdio.h>
25 namespace bzs
26 {
27 namespace db
28 {
29 namespace protocol
30 {
31 namespace tdap
32 {
33 namespace client
34 {
35 
36 
37 /** @cond INTERNAL */
38 #define MEM_ALLOC_TYPE_NONE 0
39 #define MEM_ALLOC_TYPE_ONE 1
40 #define MEM_ALLOC_TYPE_ARRAY 2
41 
42 /* This class specify memory allocation type owned.
43  If copy this object do not copy menbers.
44  Because copy destination allocation type specify destination owned.
45 */
46 class refarymem
47 {
48  union
49  {
50  refarymem* m_parent;
51  int m_refCount;
52  };
53 
54  bool m_child;
55  unsigned char m_allocType;
56 
57  virtual void releaseMemory() = 0;
58 
59 protected:
60 
61  refarymem(const refarymem& r):m_parent(NULL),
62  m_child(0), m_allocType(MEM_ALLOC_TYPE_NONE){}
63 
64  virtual ~refarymem(){}
65 
66  refarymem& operator=(const refarymem& r)
67  {
68  return *this;
69  }
70 
71  inline int allocType() {return m_allocType;}
72 
73 public:
74 
75  refarymem():m_parent(NULL), m_child(0), m_allocType(MEM_ALLOC_TYPE_NONE){}
76 
77  inline void setAllocParent(refarymem* v)
78  {
79  m_parent = v;
80  m_child = (v != NULL);
81  }
82 
83  void setAllocTypeThis(int v) { m_allocType = ( unsigned char)v; }
84 
85  void addref()
86  {
87  if (m_child)
88  m_parent->addref();
89  else if (m_allocType)
90  ++m_refCount;
91  }
92 
93  void release()
94  {
95  if (m_child)
96  m_parent->release();
97  else
98  {
99  --m_refCount;
100  if (m_refCount == 0)
101  releaseMemory();
102  }
103  }
104 
105  int refcount() const { return m_refCount; }
106 
107  bool tryFastRelease(int totalRefCount)
108  {
109  if (!m_child && (m_refCount == totalRefCount))
110  {
111  m_refCount = 1;
112  release();
113  return true;
114  }
115  return false;
116  }
117 };
118 /** @endcond */
119 
120 class autoMemory;
121 
122 /* copyable */
123 class fieldsBase : public refarymem
124 {
126  friend class recordsetImple;
127  friend class recordsetQuery;
128 
129  virtual unsigned char* ptr(int index) const = 0;
130 
131 protected:
132  /** @cond INTERNAL */
133  fielddefs* m_fns;
134  bool m_invalidRecord;
135  virtual table* tbptr() const { return NULL; }
136 
137  void throwIndexError(short index) const
138  {
139  if (tbptr())
140  {
141  tbptr()->setStat(STATUS_INVARID_FIELD_IDX);
142  nstable::throwError(_T("field access"), tbptr());
143  }
144  else
145  {
146  _TCHAR tmp[100];
147  _stprintf_s(tmp, 100, _T("field access index %d of %s"), index,
148  tbptr() ? tbptr()->tableDef()->tableName() : _T(""));
149  nstable::throwError(tmp, STATUS_INVARID_FIELD_IDX);
150  }
151  }
152 
153  explicit inline fieldsBase(fielddefs* fns)
154  : refarymem(), m_fns(fns), m_invalidRecord(false)
155  {
156  }
157 
158  inline void setFielddefs(fielddefs* def) { m_fns = def; }
159 
160  virtual void removeLastMemBlock(){};
161 
162  virtual void setRecordData(autoMemory* am, unsigned char* ptr, size_t size,
163  short* endFieldIndex, bool owner = false){};
164  /** @endcond */
165 public:
166 
167  virtual ~fieldsBase(){};
168 
169  inline void setInvalidRecord(bool v) { m_invalidRecord = v; }
170 
171  inline bool isInvalidRecord() const { return m_invalidRecord; }
172 
173  inline field getFieldNoCheck(short index) const
174  {
175  return field(ptr((short)index), (*m_fns)[(short)index], m_fns);
176  }
177 
178  inline field operator[](short index) const
179  {
180  if (m_fns->checkIndex(index))
181  return field(ptr((short)index), (*m_fns)[(short)index], m_fns);
182 
183  throwIndexError(index);
184  return field(NULL, dummyFd(), m_fns);
185  }
186 
187  inline field operator[](const _TCHAR* name) const
188  {
189  return operator[](std::_tstring(name));
190  }
191 
192  inline field operator[](const std::_tstring& name) const
193  {
194  short index = m_fns->indexByName(name);
195  return operator[](index);
196  }
197 
198  inline size_t size() const { return m_fns->size(); }
199 
200  inline field fd(short index) const { return operator[](index); }
201 
202  inline field fd(const _TCHAR* name) const
203  {
204  int index = m_fns->indexByName(name);
205  return operator[](index);
206  }
207 
208  inline short indexByName(const _TCHAR* name) const
209  {
210  return m_fns->indexByName(name);
211  }
212 
213  inline const fielddefs* fieldDefs() const { return m_fns; }
214 
215  virtual void clear() = 0;
216 };
217 
218 typedef boost::shared_ptr<database> database_ptr;
219 typedef boost::shared_ptr<table> table_ptr;
220 typedef fieldsBase row;
221 typedef row* row_ptr;
222 
223 /* copyable*/
224 class fields : public fieldsBase
225 {
226  table& m_tb;
227 
228  void releaseMemory(){}
229 
230  inline unsigned char* ptr(int index) const
231  {
232  return (unsigned char*)m_tb.data();
233  }
234 
235  table* tbptr() const { return &m_tb; }
236 
237  inline explicit fields() : fieldsBase(NULL), m_tb(*((table*)0))
238  {
239  }
240 
241 public:
242  inline explicit fields(table& tb) : fieldsBase(tb.m_fddefs), m_tb(tb) {}
243 
244  inline explicit fields(table_ptr tb)
245  : fieldsBase((*tb).m_fddefs), m_tb(*tb)
246  {
247  }
248 
249  inline void clear() { m_tb.clearBuffer(); }
250 
251  inline table& tb() const { return m_tb; }
252 
253  inline short inproc_size() const { return m_tb.getCurProcFieldCount(); }
254 
255  inline field inproc_fd(short index) const
256  {
257  return operator[](m_tb.getCurProcFieldIndex(index));
258  }
259 };
260 
261 } // namespace client
262 } // namespace tdap
263 } // namespace protocol
264 } // namespace db
265 } // namespace bzs
266 
267 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_FIELDS_H
bool isInvalidRecord() const
Definition: fields.h:171
const _TCHAR * protocol(const _TCHAR *uri)
Definition: uri.h:42
const fielddefs * fieldDefs() const
Definition: fields.h:213
friend class multiRecordAlocatorImple
Definition: fields.h:125
virtual ~fieldsBase()
Definition: fields.h:167
field fd(const _TCHAR *name) const
Definition: fields.h:202
const void * data() const
Definition: nsTable.h:158
field operator[](const _TCHAR *name) const
Definition: fields.h:187
static void throwError(const _TCHAR *caption, short statusCode)
field operator[](const std::_tstring &name) const
Definition: fields.h:192
field getFieldNoCheck(short index) const
Definition: fields.h:173
field inproc_fd(short index) const
Definition: fields.h:255
boost::shared_ptr< table > table_ptr
Definition: fields.h:219
friend class recordsetImple
Definition: fields.h:126
フィールドコレクションクラス
Definition: fields.h:224
row * row_ptr
Definition: fields.h:221
boost::shared_ptr< database > database_ptr
Definition: fields.h:218
field operator[](short index) const
Definition: fields.h:178
テーブルアクセスクラス (nocopyable)
Definition: table.h:89
void setStat(short_td v)
Definition: nsTable.h:164
fielddef のコレクションクラス
Definition: field.h:73
size_t size() const
Definition: fields.h:198
recordset フィルタリングクエリー
Definition: groupQuery.h:95
fields(table &tb)
Definition: fields.h:242
void setInvalidRecord(bool v)
Definition: fields.h:169
フィールドコレクションのベースクラス
Definition: fields.h:123
void clear()
Definition: fields.h:249
fieldsBase row
Definition: fields.h:220
short getCurProcFieldIndex(short index) const
field fd(short index) const
Definition: fields.h:200
typedef short(__STDCALL *schemaMgrFn)(database *db)
short inproc_size() const
Definition: fields.h:253
table & tb() const
Definition: fields.h:251
short indexByName(const _TCHAR *name) const
Definition: fields.h:208
fields(table_ptr tb)
Definition: fields.h:244
フィールドアクセスクラス
Definition: field.h:123

Transactd SDK 2015年09月08日(火) 19時13分35秒 doxygen