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
|
#include <precomp.h>
#include "attribute.h"
#include <api/config/items/cfgitemi.h>
Attribute::Attribute(const wchar_t *newname, const wchar_t *_desc) :
NamedW(newname), desc(_desc), cfgitemi(NULL), private_storage(NULL) { }
Attribute::~Attribute() {
delete private_storage;
}
const wchar_t *Attribute::getAttributeName() {
return NamedW::getName();
}
const wchar_t *Attribute::getAttributeDesc() {
return desc;
}
int Attribute::getValueAsInt()
{
wchar_t buf[1024]=L"";
getData(buf, 1024);
return WTOI(buf);
}
int Attribute::setValueAsInt(int newval, bool def)
{
return setData(StringPrintfW(newval), def);
}
double Attribute::getValueAsDouble()
{
wchar_t buf[1024] = {0};
getData(buf, 1024);
return WTOF(buf);
}
double Attribute::setValueAsDouble(double newval, bool def)
{
return setData(StringPrintfW(newval), def);
}
int Attribute::getDataLen() {
if (private_storage != NULL)
return (int)private_storage->len()+1;
ASSERTPR(WASABI_API_CONFIG != NULL, "getDataLen() before API");
int r = WASABI_API_CONFIG->getStringPrivateLen(mkTag());
if (r < 0) {
r = (int)default_val.len()+1;
}
return r;
}
int Attribute::getData(wchar_t *data, int data_len)
{
if (data == NULL || data_len < 0)
return 0;
if (private_storage != NULL)
{
if (private_storage->isempty())
{
if (data_len >= 1) {
*data = 0;
return 1;
}
return 0;
}
WCSCPYN(data, private_storage->getValue(), data_len);
return MIN((int)private_storage->len(), data_len);
}
ASSERTPR(WASABI_API_CONFIG != NULL, "can't get without api");
if (WASABI_API_CONFIG == NULL) return 0;
int r = WASABI_API_CONFIG->getStringPrivate(mkTag(), data, data_len, default_val.isempty() ? L"" : default_val.getValue());
return r;
}
int Attribute::setData(const wchar_t *data, bool def)
{
if (def) { // setting default value
default_val = data;
return 1;
}
ASSERTPR(WASABI_API_CONFIG != NULL, "can't set data before api");
if (WASABI_API_CONFIG == NULL) return 0;
int r = setDataNoCB(data);
if (r && cfgitemi != NULL) cfgitemi->cfgitem_onAttribSetValue(this);
return r;
}
int Attribute::setDataNoCB(const wchar_t *data)
{
if (private_storage != NULL) {
private_storage->setValue(data);
} else {
WASABI_API_CONFIG->setStringPrivate(mkTag(), data);
}
dependent_sendEvent(Attribute::depend_getClassGuid(), Event_DATACHANGE);
return 1;
}
void Attribute::setCfgItem(CfgItemI *item)
{
delete private_storage; private_storage = NULL;
ASSERT(cfgitemi == NULL || item == NULL);
cfgitemi = item;
if (cfgitemi != NULL)
{
if (cfgitemi->cfgitem_usePrivateStorage())
private_storage = new StringW;
}
}
StringW Attribute::mkTag()
{
StringW ret;
if (cfgitemi)
{
ret = cfgitemi->cfgitem_getPrefix();
}
ret.cat(getName());
return ret;
}
void Attribute::disconnect() {
setCfgItem(NULL);
}
|