forked from lballabio/quantlib-old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddindynamic1.cpp
More file actions
256 lines (179 loc) · 8.52 KB
/
Copy pathaddindynamic1.cpp
File metadata and controls
256 lines (179 loc) · 8.52 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include <ohxl/objecthandlerxl.hpp>
#include <ohxl/utilities/xlutilities.hpp>
#include <ExampleObjects/accountexample.hpp>
/* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks,
for example) also #define _MSC_VER
*/
#ifdef BOOST_MSVC
# define BOOST_LIB_DIAGNOSTIC
# include <oh/auto_link.hpp>
# include <xlsdk/auto_link.hpp>
# undef BOOST_LIB_DIAGNOSTIC
#endif
#include <sstream>
DLLEXPORT int xlAutoOpen() {
//Instantiate the Processor Factory
static ObjectHandler::ProcessorFactory processorFactory;
// Instantiate the Serialization Factory
static AccountExample::SerializationFactory factory;
static XLOPER xDll;
try {
AccountExample::registerEnumeratedTypes();
Excel(xlGetName, &xDll, 0);
Excel(xlfRegister, 0, 7, &xDll,
TempStrNoSize("\x14""addin1CreateCustomer"),// function code name
TempStrNoSize("\x06""CCCNL#"), // parameter codes
TempStrNoSize("\x14""addin1CreateCustomer"),// function display name
TempStrNoSize("\x1B""ObjectID,Name,Age,Permanent"), // comma-delimited list of parameters
TempStrNoSize("\x01""1"), // function type (0 = hidden function, 1 = worksheet function, 2 = command macro)
TempStrNoSize("\x07""Example")); // function category
Excel(xlfRegister, 0, 7, &xDll,
TempStrNoSize("\x13""addin1CreateAccount"), // function code name
TempStrNoSize("\x08""CCCCNPL#"), // parameter codes
TempStrNoSize("\x13""addin1CreateAccount"), // function display name
TempStrNoSize("\x2F""ObjectID,Customer,Type,Number,Balance,Permanent"), // comma-delimited list of parameters
TempStrNoSize("\x01""1"), // function type (0 = hidden function, 1 = worksheet function, 2 = command macro)
TempStrNoSize("\x07""Example")); // function category
Excel(xlfRegister, 0, 7, &xDll,
TempStrNoSize("\x10""addin1SetBalance"), // function code name
TempStrNoSize("\x04""LCE#"), // parameter codes
TempStrNoSize("\x10""addin1SetBalance"), // function display name
TempStrNoSize("\x10""ObjectID,Balance"), // comma-delimited list of parameters
TempStrNoSize("\x01""1"), // function type (0 = hidden function, 1 = worksheet function, 2 = command macro)
TempStrNoSize("\x07""Example")); // function category
Excel(xlfRegister, 0, 7, &xDll,
TempStrNoSize("\x05""func1"), // function code name
TempStrNoSize("\x04""CCP#"), // parameter codes
TempStrNoSize("\x05""func1"), // function code name
TempStrNoSize("\x10""ObjectID,Trigger"), // comma-delimited list of parameters
TempStrNoSize("\x01""1"), // function type (0 = hidden function, 1 = worksheet function, 2 = command macro)
TempStrNoSize("\x07""Example")); // function category
Excel(xlFree, 0, 1, &xDll);
return 1;
} catch (const std::exception &e) {
std::ostringstream err;
err << "Error loading ExampleXllDynamic1: " << e.what();
Excel(xlcAlert, 0, 1, TempStrStl(err.str()));
Excel(xlFree, 0, 1, &xDll);
return 0;
} catch (...) {
Excel(xlFree, 0, 1, &xDll);
return 0;
}
}
DLLEXPORT int xlAutoClose() {
try {
AccountExample::unregisterEnumeratedTypes();
return 1;
} catch (const std::exception &e) {
std::ostringstream err;
err << "Error unloading ExampleXllDynamic1: " << e.what();
Excel(xlcAlert, 0, 1, TempStrStl(err.str()));
return 0;
} catch (...) {
return 0;
}
}
DLLEXPORT void xlAutoFree(XLOPER *px) {
freeOper(px);
}
DLLEXPORT char *addin1CreateCustomer(
char *objectID,
char *name,
long *age,
bool *permanent) {
boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;
try {
functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>
(new ObjectHandler::FunctionCall("addin1CreateCustomer"));
boost::shared_ptr<ObjectHandler::ValueObject> valueObject(
new AccountExample::CustomerValueObject(objectID, name, *age, *permanent));
boost::shared_ptr<ObjectHandler::Object> object(
new AccountExample::CustomerObject(valueObject, name, *age, *permanent));
std::string returnValue =
ObjectHandler::RepositoryXL::instance().storeObject(objectID, object);
static char ret[XL_MAX_STR_LEN];
ObjectHandler::stringToChar(returnValue, ret);
return ret;
} catch (const std::exception &e) {
ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
return 0;
}
}
DLLEXPORT char *addin1CreateAccount(
char *objectID,
char *customer,
char *type,
long *number,
OPER *balance,
bool *permanent) {
boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;
try {
functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>
(new ObjectHandler::FunctionCall("addin1CreateAccount"));
OH_GET_REFERENCE(customerRef, customer,
AccountExample::CustomerObject, AccountExample::Customer)
double balanceDouble = ObjectHandler::convert2<double>(
ObjectHandler::ConvertOper(*balance), "balance", 100.00);
ObjectHandler::property_t balanceProperty =
ObjectHandler::convert2<ObjectHandler::property_t>(
ObjectHandler::ConvertOper(*balance), "balance");
AccountExample::Account::Type typeEnum =
ObjectHandler::Create<AccountExample::Account::Type>()(type);
boost::shared_ptr<ObjectHandler::ValueObject> valueObject(
new AccountExample::AccountValueObject(objectID, customer, type, *number, balanceProperty, *permanent));
boost::shared_ptr<ObjectHandler::Object> object(
new AccountExample::AccountObject(valueObject, customerRef, typeEnum, *number, balanceDouble, *permanent));
std::string returnValue =
ObjectHandler::RepositoryXL::instance().storeObject(objectID, object, true);
static char ret[XL_MAX_STR_LEN];
ObjectHandler::stringToChar(returnValue, ret);
return ret;
} catch (const std::exception &e) {
ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
return 0;
}
}
DLLEXPORT short int *addin1SetBalance(char *objectID, double *balance) {
boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;
try {
functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>
(new ObjectHandler::FunctionCall("addin1SetBalance"));
OH_GET_OBJECT(accountObject, objectID, AccountExample::AccountObject)
accountObject->setBalance(*balance);
static short int ret = TRUE;
return &ret;
} catch (const std::exception &e) {
ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
return 0;
}
}
DLLEXPORT char *func1(char *objectID, OPER *trigger) {
boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;
try {
functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>
(new ObjectHandler::FunctionCall("func1"));
AccountExample::Account::Type accountTypeEnum =
ObjectHandler::Create<AccountExample::Account::Type>()(objectID);
std::ostringstream s;
s << accountTypeEnum;
static char ret[XL_MAX_STR_LEN];
ObjectHandler::stringToChar(s.str(), ret);
return ret;
} catch (const std::exception &e) {
ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
return 0;
}
}