全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
myDateTime.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_MYDATETIME_H
2 #define BZS_DB_PROTOCOL_TDAP_MYDATETIME_H
3 /*=================================================================
4  Copyright (C) 2015 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 <tchar.h>
22 #include <bzs/env/compiler.h>
23 #include <stddef.h>
24 
25 namespace bzs
26 {
27 namespace db
28 {
29 namespace protocol
30 {
31 namespace tdap
32 {
33 /** @cond INTERNAL */
34 
35 #pragma pack(push, 1)
37 
38 struct PACKAGE myDate
39 {
40  union
41  {
42  struct
43  {
44  unsigned int dd : 5;
45  unsigned int mm : 4;
46  unsigned int yy : 15;
47  unsigned int tmp : 8;
48  };
49  int i;
50  };
51  inline myDate() {};
52  inline myDate(int /*dec*/, bool /*bigendian*/) {};
53  void setValue(int v, bool btrDate_i = false);
54  int getValue(bool btrvValue = false);
55  char* toString(char* p, size_t size, bool w3_format = false);
56  myDate& operator=(const char* p);
57 #ifdef _WIN32
58  wchar_t* toString(wchar_t* p, size_t size, bool w3_format = false);
59  myDate& operator=(const wchar_t* p);
60 #endif
61  inline __int64 internalValue() const { return i; }
62  inline void setInternalValue(__int64 v) { i = (int)v; }
63 };
64 
65 struct PACKAGE myTime
66 {
67 
68 protected:
69  int m_dec;
70  bool m_bigendian;
71 public:
72  union
73  {
74  struct
75  {
76  unsigned __int64 ms : 24;
77  unsigned __int64 ss : 6;
78  unsigned __int64 nn : 6;
79  unsigned __int64 hh : 10;
80  unsigned __int64 unused : 1;
81  unsigned __int64 sign : 1;
82  unsigned __int64 tmp : 16;
83  };
84  __int64 i64;
85  };
86 
87 public:
88  inline myTime(int dec, bool bigendian) : m_dec(dec),
89  m_bigendian(bigendian){};
90  virtual void setValue(__int64 v, bool btrTime_i = false);
91  virtual __int64 getValue(bool btrTime_i = false);
92  char* toString(char* p, size_t size);
93  myTime& operator=(const char* p);
94 #ifdef _WIN32
95  wchar_t* toString(wchar_t* p, size_t size);
96  myTime& operator=(const wchar_t* p);
97 #endif
98  inline __int64 internalValue() const { return i64; }
99  inline void setInternalValue(__int64 v) { i64 = v; }
100 };
101 
102 struct PACKAGE maTime : public myTime
103 {
104  virtual void setValue(__int64 v, bool btrTime_i = false);
105  virtual __int64 getValue(bool btrTime_i = false);
106 public:
107  inline maTime(int dec, bool bigendian) : myTime(dec, bigendian){}
108  maTime& operator=(const char* p);
109 #ifdef _WIN32
110  maTime& operator=(const wchar_t* p) ;
111 #endif
112 };
113 
114 struct PACKAGE myDateTime
115 {
116 protected:
117  int m_dec;
118  bool m_bigendian;
119 public:
120  union
121  {
122  struct
123  {
124  unsigned __int64 ms : 24;
125  unsigned __int64 ss : 6;
126  unsigned __int64 nn : 6;
127  unsigned __int64 hh : 5;
128  unsigned __int64 dd : 5;
129  unsigned __int64 yymm : 17; // yy*13+mm (yy 0-9999, mm 0-12)
130  unsigned __int64 sign : 1; //always 1 0 is reserved
131  };
132  __int64 i64;
133  };
134 
135  inline myDateTime(int dec, bool bigendian) : m_dec(dec), m_bigendian(bigendian){};
136  virtual void setValue(__int64 v);
137  virtual __int64 getValue();
138  char* toString(char* p, size_t size) const;
139  myDateTime& operator=(const char* p);
140  char* dateStr(char* p, size_t size) const;
141  char* timeStr(char* p, size_t size) const;
142  void setTime(const char* p);
143 
144 #ifdef _WIN32
145  wchar_t* toString(wchar_t* p, size_t size) const ;
146  myDateTime& operator=(const wchar_t* p) ;
147  wchar_t* dateStr(wchar_t* p, size_t size) const;
148  wchar_t* timeStr(wchar_t*, size_t size) const;
149  void setTime(const wchar_t* p);
150 #endif
151  inline __int64 internalValue() const { return i64; }
152  inline void setInternalValue(__int64 v) { i64 = v; }
153 };
154 
155 struct PACKAGE maDateTime : public myDateTime
156 {
157  virtual void setValue(__int64 v);
158  virtual __int64 getValue();
159 public:
160  inline maDateTime(int dec, bool bigendian) : myDateTime(dec, bigendian){};
161  maDateTime& operator=(const char* p);
162 #ifdef _WIN32
163  maDateTime& operator=(const wchar_t* p) ;
164 #endif
165 };
166 
167 struct PACKAGE myTimeStamp
168 {
169 private:
170  int m_dec;
171  bool m_bigendian;
172 protected:
173  bool m_mariadb;
174 public:
175  union
176  {
177  struct
178  {
179  unsigned __int64 ms : 24;
180  unsigned __int64 datetime : 32;
181  unsigned __int64 tmp : 8;
182  };
183  __int64 i64;
184  };
185 
186  inline myTimeStamp(int dec, bool bigendian) : m_dec(dec),
187  m_bigendian(bigendian), m_mariadb(false){};
188  void setValue(__int64 v);
189  __int64 getValue();
190  char* toString(char* p, size_t size);
191  myTimeStamp& operator=(const char* p);
192  char* dateStr(char* p, size_t size) const;
193  char* timeStr(char* p, size_t size) const;
194 
195 #ifdef _WIN32
196  wchar_t* toString(wchar_t* p, size_t size);
197  myTimeStamp& operator=(const wchar_t* p);
198  wchar_t* dateStr(wchar_t* p, size_t size) const;
199  wchar_t* timeStr(wchar_t* p, size_t size) const;
200 #endif
201  inline __int64 internalValue() const { return i64; }
202  inline void setInternalValue(__int64 v) { i64 = v; }
203 };
204 
205 
206 struct PACKAGE maTimeStamp : public myTimeStamp
207 {
208 
209  inline maTimeStamp (int dec, bool bigendian) : myTimeStamp(dec, bigendian)
210  {
211  m_mariadb = true;
212  }
213  inline maTimeStamp& operator=(const char* p){ myTimeStamp::operator=(p); return *this;}
214 #ifdef _WIN32
215  inline maTimeStamp& operator=(const wchar_t* p) { myTimeStamp::operator=(p); return *this; }
216 #endif
217 };
218 
219 inline int btrdateToMydate(int btrd)
220 {
221  myDate myd;
222  myd.setValue(btrd, true);
223  return myd.i;
224 }
225 
226 // Do not work at maridab
227 inline __int64 btrtimeToMytime(int btrTime_i, bool bigendian)
228 {
229  myTime myt(4, bigendian);
230  myt.setValue(btrTime_i, true);
231  return myt.i64;
232 }
233 
234 inline int mydateToBtrdate(int myDate_i)
235 {
236  myDate myd;
237  myd.i = myDate_i;
238  return myd.getValue(true);
239 }
240 
241 inline int mytimeToBtrtime(__int64 myTime_i, bool bigendian, int dec)
242 {
243  myTime myt(dec, bigendian);
244  myt.i64 = myTime_i;
245  return (int)myt.getValue(true);
246 }
247 
248 template <class T>
249 __int64 getInternalValue(int dec, bool bigendian, __int64 value)
250 {
251  T t(dec, bigendian);
252  t.setValue(value);
253  return t.internalValue();
254 }
255 
256 template <class T>
257 __int64 getStoreValue(int dec, bool bigendian, __int64 value)
258 {
259  T t(dec, bigendian);
260  t.setInternalValue(value);
261  return t.getValue();
262 }
263 
264 #pragma warning(disable : 4244)
265 template <class T, typename CHAR>
266 const CHAR* date_time_str(int dec, bool bigendian, __int64 value, CHAR* buf, size_t size)
267 {
268  T t(dec, bigendian);
269  t.setValue(value);
270  return t.toString(buf, size);
271 }
272 
273 template <class T, class T2>
274 inline __int64 str_to_64(int dec, bool bigendian, const T2* data)
275 {
276  T t(dec, bigendian);
277  t = data;
278  return t.getValue();
279 }
280 
281 #pragma warning(default : 4244)
282 
283 
284 
285 #pragma pack(pop)
286 pragma_pop;
287 /** @endcond */
288 
289 } // namespace tdap
290 } // namespace protocol
291 } // namespace db
292 } // namespace bzs
293 
294 #endif //BZS_DB_PROTOCOL_TDAP_MYDATETIME_H
pragma_pop
Definition: btrDate.h:107
pragma_pack1
Definition: btrDate.h:36

Transactd SDK 2018年07月31日(火) 19時40分21秒 doxygen