-
Notifications
You must be signed in to change notification settings - Fork 9
/
cxbusiness.h
199 lines (142 loc) · 6.31 KB
/
cxbusiness.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#ifndef CXBUSINESS_H
#define CXBUSINESS_H
#include "cxglobal.h"
const std::string CS_SectionMsObjectTypes = "MsObjectTypes";
class CxMsObjectType
{
public:
enum StructType_Enum {StructType_None, StructType_Simple, StructType_Main};
inline CxMsObjectType() {
_howLongStore = 0;
}
inline CxMsObjectType(const std::string & typeName, StructType_Enum structType, const std::vector<std::string> & majorKeies, const std::string & detailKey, timems_t msHowLongStore) {
_typeName = typeName;
_structType = structType;
_majorKeies = majorKeies;
_detailKey = detailKey;
_howLongStore = msHowLongStore;
}
inline CxMsObjectType(const CxMsObjectType & other) {
assignFrom(other);
}
inline CxMsObjectType &operator=(const CxMsObjectType &other)
{
if (this != &other)
{
assignFrom(other);
}
return *this;
}
inline void assignFrom(const CxMsObjectType & other) {
_typeName = other._typeName;
_structType = other._structType;
_majorKeies = other._majorKeies;
_detailKey = other._detailKey;
_howLongStore = other._howLongStore;
}
const std::string & typeName() const { return _typeName; }
StructType_Enum structType() const { return _structType; }
const std::vector<std::string> & majorKeies() const { return _majorKeies; }
const std::string & detailKey() const { return _detailKey; }
private:
std::string _typeName;
StructType_Enum _structType; // main detail table
std::vector<std::string> _majorKeies; // main table field name
std::string _detailKey; // detail table major key name
msepoch_t _howLongStore; //
friend class CxMsObjectTypeManager;
};
class GM_CCXX_CORE_API CxMsObjectTypeManager
{
public:
static void start();
static int load();
static const CxMsObjectType * find(const std::string & sTypeName);
static std::string name(const std::string & sTypeName, const std::map<std::string, std::string> & aMajor);
static bool isTempObject(const std::string & sTypeName);
};
class GM_CCXX_CORE_API CxMsObjectData
{
public:
inline CxMsObjectData() : _majorModify(false), _objectType(NULL) {}
inline CxMsObjectData(const std::string & sTypeName, const std::string & sName, const std::map<std::string, std::string> & aMajor) : _majorModify(false), _objectType(NULL) {
_typeName = sTypeName;
_name = sName;
_major = aMajor;
}
inline CxMsObjectData(const std::string & sTypeName, const std::string & sName, const std::map<std::string, std::string> & aMajor, const std::map<std::string, std::map<std::string, std::string> > & details) : _majorModify(false), _objectType(NULL) {
_typeName = sTypeName;
_name = sName;
_major = aMajor;
_details = details;
}
inline CxMsObjectData(const std::string & sText) : _majorModify(false), _objectType(NULL) {
fromString(sText);
}
inline CxMsObjectData(const CxMsObjectData & other) : _majorModify(false), _objectType(NULL) {
assignFrom(other);
}
inline CxMsObjectData &operator=(const CxMsObjectData &other)
{
if (this != &other)
{
assignFrom(other);
}
return *this;
}
inline void assignFrom(const CxMsObjectData & other) {
_typeName = other._typeName;
_name = other._name;
_major = other._major;
_details = other._details;
}
inline const std::string & typeName() const { return _typeName; }
const CxMsObjectType * getMsObjectType() const;
inline const std::string & name() const { return _name; }
inline const std::map<std::string, std::map<std::string, std::string> > & details() const { return _details; }
inline bool majorModify() const { return _majorModify; }
inline const std::map<std::string, int> & detailModifies() const { return _detailModifies; }
std::string toString() const;
int fromString(const std::string & sText);
int updateMajor(const std::map<std::string, std::string> & aMajor);
int updateDetails(const std::map<std::string, std::map<std::string, std::string> > & details);
private:
std::string _typeName;
std::string _name; // major key value
std::map<std::string, std::string> _major; // main table content
std::map<std::string, std::map<std::string, std::string> > _details; // detail table content
bool _majorModify;
std::map<std::string, int> _detailModifies;
int _source;
CxMsObjectType * _objectType;
private:
inline void setTypeName(const std::string & value) { _typeName = value; }
inline void setName(const std::string & value) { _name = value; }
friend class CxMsObjectDataManager;
};
class CxIMsObjectDataSubject
{
protected:
virtual void msObject_changed(const CxMsObjectData & oMsObject, int iChangeType) = 0;
virtual void msObjects_changed(const std::string & sTypeName, const std::vector<std::string> & sNames) = 0;
friend class CxMsObjectDataManager;
};
class GM_CCXX_CORE_API CxMsObjectDataManager
{
public:
static void addObserver(CxIMsObjectDataSubject * oSubject);
static void removeObserver(CxIMsObjectDataSubject* oSubject);
static void beginReceived(const std::string & sTypeName, int iSource = 0);
static int receivedObject(const std::string & sTypeName, const std::string & sName, const std::map<std::string, std::string> & aMajor);
static int receivedObject(const std::string & sTypeName, const std::string & sName, const std::map<std::string, std::string> & aMajor, const std::map<std::string, std::map<std::string, std::string> > & details);
static int receivedObject(const CxMsObjectData * oMsObject, bool bReplace = false);
static void endReceived();
static const std::vector<CxMsObjectData> & msObjects();
static std::vector<const CxMsObjectData *> findObjects(const std::string & sTypeName);
static std::vector<const CxMsObjectData *> findObjects(const std::string & sTypeName, const std::vector<std::string> & sNames);
static const CxMsObjectData * find(const std::string & sTypeName, const std::string & majorKey, const std::string & majorValue);
static int saveMsObjects(const std::string & sFilePath);
private:
static CxMsObjectData * find(const std::string & sTypeName, const std::string & sName);
};
#endif // CXBUSINESS_H