Hikyuu
StockTypeInfo_serialization.h
浏览该文件的文档.
1 /*
2  * StockTypeInfo.h
3  *
4  * Created on: 2013-5-1
5  * Author: fasiondog
6  */
7 
8 #ifndef STOCKTYPEINFO_SERIALIZATION_H_
9 #define STOCKTYPEINFO_SERIALIZATION_H_
10 
11 #include "../config.h"
12 #include "../StockTypeInfo.h"
13 #include "../utilities/util.h"
14 
15 #if HKU_SUPPORT_SERIALIZATION
16 #include <boost/serialization/nvp.hpp>
17 #include <boost/serialization/split_free.hpp>
18 
19 namespace boost {
20 namespace serialization {
21 
22 //防止boost::serialization某些情况不能在独立的命名空间中
23 #if defined(BOOST_WINDOWS) && (PY_VERSION_HEX < 0x03000000)
24  #ifndef HKU_GB_TO_UTF8
25  #define HKU_GB_TO_UTF8(s) hku::GBToUTF8(s)
26  #endif
27 
28  #ifndef HKU_UTF8_TO_GB
29  #define HKU_UTF8_TO_GB(s) hku::UTF8ToGB(s)
30  #endif
31 #else
32  #ifndef HKU_GB_TO_UTF8
33  #define HKU_GB_TO_UTF8(s) (s)
34  #endif
35 
36  #ifndef HKU_UTF8_TO_GB
37  #define HKU_UTF8_TO_GB(s) (s)
38  #endif
39 #endif
40 
41 template<class Archive>
42 void save(Archive & ar, const hku::StockTypeInfo& record, unsigned int version) {
43  hku::hku_uint32 type = record.type();
44  hku::string description = HKU_GB_TO_UTF8(record.description());
45  hku::price_t tick = record.tick();
46  hku::price_t tickValue = record.tickValue();
47  int precision = record.precision();
48  size_t minTradeNumber = record.minTradeNumber();
49  size_t maxTradeNumber = record.maxTradeNumber();
50  ar & BOOST_SERIALIZATION_NVP(type);
51  ar & BOOST_SERIALIZATION_NVP(description);
52  ar & BOOST_SERIALIZATION_NVP(tick);
53  ar & BOOST_SERIALIZATION_NVP(tickValue);
54  ar & BOOST_SERIALIZATION_NVP(precision);
55  ar & BOOST_SERIALIZATION_NVP(minTradeNumber);
56  ar & BOOST_SERIALIZATION_NVP(maxTradeNumber);
57 }
58 
59 template<class Archive>
60 void load(Archive & ar, hku::StockTypeInfo& record, unsigned int version) {
61  hku::hku_uint32 type;
62  hku::string description;
63  hku::price_t tick, tickValue;
64  int precision;
65  size_t minTradeNumber, maxTradeNumber;
66  ar & BOOST_SERIALIZATION_NVP(type);
67  ar & BOOST_SERIALIZATION_NVP(description);
68  ar & BOOST_SERIALIZATION_NVP(tick);
69  ar & BOOST_SERIALIZATION_NVP(tickValue);
70  ar & BOOST_SERIALIZATION_NVP(precision);
71  ar & BOOST_SERIALIZATION_NVP(minTradeNumber);
72  ar & BOOST_SERIALIZATION_NVP(maxTradeNumber);
73  record = hku::StockTypeInfo(type, HKU_UTF8_TO_GB(description),
74  tick, tickValue, precision, minTradeNumber, maxTradeNumber);
75 }
76 }} /* namespace boost::serailization */
77 
78 BOOST_SERIALIZATION_SPLIT_FREE(hku::StockTypeInfo)
79 
80 #endif /* HKU_SUPPORT_SERIALIZATION */
81 
82 #endif /* STOCKTYPEINFO_SERIALIZATION_H_ */
unsigned hku_uint32
Definition: DataType.h:48
#define HKU_GB_TO_UTF8(s)
Definition: StockTypeInfo_serialization.h:33
Definition: Block_serialization.h:17
std::string string
Definition: DataType.h:55
证券类型信息
Definition: StockTypeInfo.h:32
#define HKU_UTF8_TO_GB(s)
Definition: StockTypeInfo_serialization.h:37
int precision() const
获取价格精度
Definition: StockTypeInfo.h:55
void load(Archive &ar, hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:34
size_t maxTradeNumber() const
获取每笔最大交易数量
Definition: StockTypeInfo.h:61
size_t minTradeNumber() const
获取每笔最小交易数量
Definition: StockTypeInfo.h:58
price_t tick() const
获取最小跳动量
Definition: StockTypeInfo.h:46
void save(Archive &ar, const hku::Block &blk, unsigned int version)
Definition: Block_serialization.h:20
double price_t
Definition: DataType.h:53
const string & description() const
获取证券类型描述信息
Definition: StockTypeInfo.h:43
price_t tickValue() const
每tick价格
Definition: StockTypeInfo.h:49
hku_uint32 type() const
获取证券类型
Definition: StockTypeInfo.h:40