00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #define ULXR_USE_INTRINSIC_VALUE_TYPES
00036
00037
00038
00039
00040
00041
00042 #define ULXR_STRUCT_MEMBER_FROM_NAME_VALUE
00043
00044
00045 #define ULXR_NEED_EXPORTS
00046 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00047
00048 #include <cstdio>
00049 #include <ctime>
00050 #include <vector>
00051
00052 #include <ulxmlrpcpp/ulxr_value.h>
00053 #include <ulxmlrpcpp/ulxr_valueparse_wb.h>
00054 #include <ulxmlrpcpp/ulxr_except.h>
00055 #include <ulxmlrpcpp/ulxr_htmlform_handler.h>
00056
00057 #ifndef ULXR_OMIT_REENTRANT_PROTECTOR
00058 #include <ulxmlrpcpp/ulxr_mutex.h>
00059 #endif
00060
00061
00062 #define ULXR_ASSERT_RPCTYPE(x) \
00063 if (x != getType() ) \
00064 { \
00065 throw ParameterException(ApplicationError, (CppString) \
00066 ULXR_PCHAR("Value type mismatch.\n") \
00067 ULXR_PCHAR("Expected: ") + ULXR_GET_STRING(#x) + ULXR_PCHAR(".\n") \
00068 ULXR_PCHAR("Actually have: ") +getTypeName() + ULXR_PCHAR(".")); \
00069 }
00070
00071
00072 namespace ulxr {
00073
00074
00075
00077
00078
00079 ULXR_API_IMPL(bool) Value::isVoid() const
00080 {
00081 return baseVal->isVoid();
00082 }
00083
00084
00085 ULXR_API_IMPL(bool) Value::isBoolean() const
00086 {
00087 return baseVal->isBoolean();
00088 }
00089
00090
00091 ULXR_API_IMPL(bool) Value::isInteger() const
00092 {
00093 return baseVal->isInteger();
00094 }
00095
00096
00097 ULXR_API_IMPL(bool) Value::isDouble() const
00098 {
00099 return baseVal->isDouble();
00100 }
00101
00102
00103 ULXR_API_IMPL(bool) Value::isArray() const
00104 {
00105 return baseVal->isArray();
00106 }
00107
00108
00109 ULXR_API_IMPL(bool) Value::isStruct() const
00110 {
00111 return baseVal->isStruct();
00112 }
00113
00114
00115 ULXR_API_IMPL(bool) Value::isString() const
00116 {
00117 return baseVal->isString();
00118 }
00119
00120
00121 ULXR_API_IMPL(bool) Value::isBase64() const
00122 {
00123 return baseVal->isBase64();
00124 }
00125
00126
00127 ULXR_API_IMPL(bool) Value::isDateTime() const
00128 {
00129 return baseVal->isDateTime();
00130 }
00131
00132
00133 ULXR_API_IMPL(ValueType) Value::getType() const
00134 {
00135 return baseVal->getType();
00136 }
00137
00138
00139 ULXR_API_IMPL(CppString) Value::getTypeName() const
00140 {
00141 return baseVal->getTypeName();
00142 }
00143
00144
00145 ULXR_API_IMPL(CppString) Value::getSignature(bool deep) const
00146 {
00147 CppString s;
00148 if (baseVal != 0)
00149 s = baseVal->getSignature(deep);
00150 return s;
00151 }
00152
00153
00154 ULXR_API_IMPL(CppString) Value::getXml(int indent) const
00155 {
00156 CppString ret;
00157 if (baseVal != 0)
00158 ret = baseVal->getXml(indent);
00159 return ret;
00160 }
00161
00162
00163 ULXR_API_IMPL(std::string) Value::getWbXml() const
00164 {
00165 std::string ret;
00166 if (baseVal != 0)
00167 ret = baseVal->getWbXml();
00168 return ret;
00169 }
00170
00171
00172 ULXR_API_IMPL(Struct*) Value::getStruct()
00173 {
00174 ULXR_ASSERT_RPCTYPE(RpcStruct);
00175 return structVal;
00176 };
00177
00178
00179 ULXR_API_IMPL(const Struct*) Value::getStruct() const
00180 {
00181 ULXR_ASSERT_RPCTYPE(RpcStruct);
00182 return structVal;
00183 };
00184
00185
00186 ULXR_API_IMPL(Array*) Value::getArray()
00187 {
00188 ULXR_ASSERT_RPCTYPE(RpcArray);
00189 return arrayVal;
00190 };
00191
00192
00193 ULXR_API_IMPL(const Array*) Value::getArray() const
00194 {
00195 ULXR_ASSERT_RPCTYPE(RpcArray);
00196 return arrayVal;
00197 };
00198
00199
00200 ULXR_API_IMPL0 Value::operator Boolean& ()
00201 {
00202 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00203 return *boolVal;
00204 }
00205
00206
00207 ULXR_API_IMPL0 Value::operator const Boolean& () const
00208 {
00209 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00210 return *boolVal;
00211 }
00212
00213
00214 ULXR_API_IMPL0 Value::operator Integer& ()
00215 {
00216 ULXR_ASSERT_RPCTYPE(RpcInteger);
00217 return *intVal;
00218 }
00219
00220
00221 ULXR_API_IMPL0 Value::operator const Integer& () const
00222 {
00223 ULXR_ASSERT_RPCTYPE(RpcInteger);
00224 return *intVal;
00225 }
00226
00227
00228 ULXR_API_IMPL0 Value::operator Double& ()
00229 {
00230 ULXR_ASSERT_RPCTYPE(RpcDouble);
00231 return *doubleVal;
00232 }
00233
00234
00235 ULXR_API_IMPL0 Value::operator const Double& () const
00236 {
00237 ULXR_ASSERT_RPCTYPE(RpcDouble);
00238 return *doubleVal;
00239 }
00240
00241
00242 ULXR_API_IMPL0 Value::operator Array& ()
00243 {
00244 ULXR_ASSERT_RPCTYPE(RpcArray);
00245 return *arrayVal;
00246 }
00247
00248
00249 ULXR_API_IMPL0 Value::operator const Array& () const
00250 {
00251 ULXR_ASSERT_RPCTYPE(RpcArray);
00252 return *arrayVal;
00253 }
00254
00255
00256 ULXR_API_IMPL0 Value::operator Struct& ()
00257 {
00258 ULXR_ASSERT_RPCTYPE(RpcStruct);
00259 return *structVal;
00260 }
00261
00262
00263 ULXR_API_IMPL0 Value::operator const Struct& () const
00264 {
00265 ULXR_ASSERT_RPCTYPE(RpcStruct);
00266 return *structVal;
00267 }
00268
00269
00270 ULXR_API_IMPL0 Value::operator RpcString& ()
00271 {
00272 ULXR_ASSERT_RPCTYPE(RpcStrType);
00273 return *stringVal;
00274 }
00275
00276
00277 ULXR_API_IMPL0 Value::operator const RpcString& () const
00278 {
00279 ULXR_ASSERT_RPCTYPE(RpcStrType);
00280 return *stringVal;
00281 }
00282
00283
00284 ULXR_API_IMPL0 Value::operator Base64& ()
00285 {
00286 ULXR_ASSERT_RPCTYPE(RpcBase64);
00287 return *base64Val;
00288 }
00289
00290
00291 ULXR_API_IMPL0 Value::operator const Base64& () const
00292 {
00293 ULXR_ASSERT_RPCTYPE(RpcBase64);
00294 return *base64Val;
00295 }
00296
00297
00298 ULXR_API_IMPL0 Value::operator DateTime& ()
00299 {
00300 ULXR_ASSERT_RPCTYPE(RpcDateTime);
00301 return *dateVal;
00302 }
00303
00304
00305 ULXR_API_IMPL0 Value::operator const DateTime& () const
00306 {
00307 ULXR_ASSERT_RPCTYPE(RpcDateTime);
00308 return *dateVal;
00309 }
00310
00311
00312 ULXR_API_IMPL0 Value::Value ()
00313 {
00314 voidVal = new Void();
00315 }
00316
00317
00318 ULXR_API_IMPL0 Value::Value (const Value &val)
00319 {
00320 baseVal = val.baseVal->cloneValue();
00321 }
00322
00323
00324 ULXR_API_IMPL0 Value::Value (const Boolean &val)
00325 {
00326 boolVal = new Boolean(val);
00327 }
00328
00329
00330 ULXR_API_IMPL0 Value::Value (const Integer &val)
00331 {
00332 intVal = new Integer(val);
00333 }
00334
00335
00336 ULXR_API_IMPL0 Value::Value (const Double &val)
00337 {
00338 doubleVal = new Double(val);
00339 }
00340
00341
00342 ULXR_API_IMPL0 Value::Value (const Array &val)
00343 {
00344 arrayVal = new Array(val);
00345 }
00346
00347
00348 ULXR_API_IMPL0 Value::Value (const Struct &val)
00349 {
00350 structVal = new Struct(val);
00351 }
00352
00353
00354 ULXR_API_IMPL0 Value::Value (const RpcString &val)
00355 {
00356 stringVal = new RpcString(val);
00357 }
00358
00359
00360 ULXR_API_IMPL0 Value::Value (const Base64 &val)
00361 {
00362 base64Val = new Base64(val);
00363 }
00364
00365
00366
00367 ULXR_API_IMPL0 Value::Value (const DateTime &val)
00368 {
00369 dateVal = new DateTime(val);
00370 }
00371
00372
00373 #ifdef ULXR_USE_INTRINSIC_VALUE_TYPES
00374
00375
00376 ULXR_API_IMPL0 Value::Value (const char *val)
00377 {
00378 stringVal = new RpcString(val);
00379 }
00380
00381
00382 #ifdef ULXR_UNICODE
00383
00384 ULXR_API_IMPL0 Value::Value (const wchar_t *val)
00385 {
00386 Cpp16BitString wstr = val;
00387 stringVal = new RpcString(unicodeToUtf8(wstr));
00388 }
00389
00390 #endif
00391
00392
00393 ULXR_API_IMPL0 Value::Value (const double &val)
00394 {
00395 doubleVal = new Double(val);
00396 }
00397
00398
00399 ULXR_API_IMPL0 Value::Value (const int &val)
00400 {
00401 intVal = new Integer(val);
00402 }
00403
00404
00405 ULXR_API_IMPL0 Value::Value (const bool &val)
00406 {
00407 boolVal = new Boolean(val);
00408 }
00409
00410
00411 #endif
00412
00413
00414 ULXR_API_IMPL(Value &) Value::operator= (const Value &val)
00415 {
00416 ValueBase *temp = val.baseVal->cloneValue();
00417 delete baseVal;
00418 baseVal = temp;
00419 return *this;
00420 }
00421
00422
00423 ULXR_API_IMPL0 Value::~Value ()
00424
00425 {
00426 delete baseVal;
00427 baseVal = 0;
00428 }
00429
00430
00432
00433
00434 ULXR_API_IMPL0 ValueBase::ValueBase (ValueType t)
00435 : type(t)
00436 {
00437 }
00438
00439
00440 ULXR_API_IMPL(ValueType) ValueBase::getType() const
00441 {
00442 return type;
00443 }
00444
00445
00446 ULXR_API_IMPL0 ValueBase::~ValueBase ()
00447 {
00448 }
00449
00450
00451 ULXR_API_IMPL(bool) ValueBase::isVoid() const
00452 {
00453 return type == RpcVoid;
00454 }
00455
00456
00457 ULXR_API_IMPL(bool) ValueBase::isBoolean() const
00458 {
00459 return type == RpcBoolean;
00460 }
00461
00462
00463 ULXR_API_IMPL(bool) ValueBase::isInteger() const
00464 {
00465 return type == RpcInteger;
00466 }
00467
00468
00469 ULXR_API_IMPL(bool) ValueBase::isDouble() const
00470 {
00471 return type == RpcDouble;
00472 }
00473
00474
00475 ULXR_API_IMPL(bool) ValueBase::isArray() const
00476 {
00477 return type == RpcArray;
00478 }
00479
00480
00481 ULXR_API_IMPL(bool) ValueBase::isStruct() const
00482 {
00483 return type == RpcStruct;
00484 }
00485
00486
00487 ULXR_API_IMPL(bool) ValueBase::isString() const
00488 {
00489 return type == RpcStrType;
00490 }
00491
00492
00493 ULXR_API_IMPL(bool) ValueBase::isBase64() const
00494 {
00495 return type == RpcBase64;
00496 }
00497
00498
00499 ULXR_API_IMPL(bool) ValueBase::isDateTime() const
00500 {
00501 return type == RpcDateTime;
00502 }
00503
00504
00505 ULXR_API_IMPL(CppString) ValueBase::getTypeName() const
00506 {
00507 CppString ret = ULXR_PCHAR("RpcValue");
00508 switch(getType() )
00509 {
00510 case RpcVoid:
00511 ret = ULXR_PCHAR("RpcVoid");
00512 break;
00513
00514 case RpcInteger:
00515 ret = ULXR_PCHAR("RpcInteger");
00516 break;
00517
00518 case RpcDouble:
00519 ret = ULXR_PCHAR("RpcDouble");
00520 break;
00521
00522 case RpcBoolean:
00523 ret = ULXR_PCHAR("RpcBoolean");
00524 break;
00525
00526 case RpcStrType:
00527 ret = ULXR_PCHAR("RpcString");
00528 break;
00529
00530 case RpcDateTime:
00531 ret = ULXR_PCHAR("RpcDateTime");
00532 break;
00533
00534 case RpcBase64:
00535 ret = ULXR_PCHAR("RpcBase64");
00536 break;
00537
00538 case RpcArray:
00539 ret = ULXR_PCHAR("RpcArray");
00540 break;
00541
00542 case RpcStruct:
00543 ret = ULXR_PCHAR("RpcStruct");
00544 break;
00545 }
00546 return ret;
00547 }
00548
00549
00551
00552
00553 ULXR_API_IMPL0 Void::Void ()
00554 : ValueBase(RpcVoid)
00555 {
00556 }
00557
00558
00559 ULXR_API_IMPL0 Void::~Void ()
00560 {
00561 }
00562
00563
00564 ULXR_API_IMPL(ValueBase *) Void::cloneValue() const
00565 {
00566 ULXR_ASSERT_RPCTYPE(RpcVoid);
00567 return new Void(*this);
00568 }
00569
00570
00571 ULXR_API_IMPL(CppString) Void::getSignature(bool ) const
00572 {
00573 ULXR_ASSERT_RPCTYPE(RpcVoid);
00574 return getValueName();
00575 }
00576
00577
00578 ULXR_API_IMPL(CppString) Void::getValueName()
00579 {
00580 return ULXR_PCHAR("void");
00581 }
00582
00583
00584 ULXR_API_IMPL(std::string) Void::getWbXml() const
00585 {
00586 ULXR_ASSERT_RPCTYPE(RpcVoid);
00587 return "";
00588 }
00589
00590
00591 ULXR_API_IMPL(CppString) Void::getXml(int ) const
00592 {
00593 ULXR_ASSERT_RPCTYPE(RpcVoid);
00594 return ULXR_PCHAR("");
00595 }
00596
00597
00599
00600
00601 ULXR_API_IMPL0 Boolean::Boolean ()
00602 : ValueBase(RpcBoolean)
00603 {
00604 }
00605
00606
00607 ULXR_API_IMPL0 Boolean::Boolean (bool b)
00608 : ValueBase(RpcBoolean), val(b)
00609 {
00610 }
00611
00612
00613 ULXR_API_IMPL0 Boolean::~Boolean ()
00614 {
00615 }
00616
00617
00618 ULXR_API_IMPL0 Boolean::Boolean (const CppString &s)
00619 : ValueBase(RpcBoolean)
00620 {
00621 if ( s == ULXR_PCHAR("true") || s == ULXR_PCHAR("TRUE")
00622 || s == ULXR_PCHAR("1") || s == ULXR_PCHAR("on") || s == ULXR_PCHAR("ON"))
00623 val = true;
00624 else
00625 val = false;
00626 }
00627
00628
00629 ULXR_API_IMPL(ValueBase *) Boolean::cloneValue() const
00630 {
00631 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00632 return new Boolean(*this);
00633 }
00634
00635
00636 ULXR_API_IMPL(CppString) Boolean::getSignature(bool ) const
00637 {
00638 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00639 return getValueName();
00640 }
00641
00642
00643 ULXR_API_IMPL(CppString) Boolean::getValueName()
00644 {
00645 return ULXR_PCHAR("bool");
00646 }
00647
00648
00649 ULXR_API_IMPL(std::string) Boolean::getWbXml() const
00650 {
00651 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00652 std::string s;
00653
00654 s = ValueParserWb::wbToken_Value;
00655 s += ValueParserWb::wbToken_Boolean;
00656
00657 if (val)
00658 s += getWbXmlString(ULXR_PCHAR("1"));
00659 else
00660 s += getWbXmlString(ULXR_PCHAR("0"));
00661
00662 s += WbXmlParser::wbxml_END;
00663 s += WbXmlParser::wbxml_END;
00664 return s;
00665 }
00666
00667
00668 ULXR_API_IMPL(CppString) Boolean::getXml(int indent) const
00669 {
00670 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00671 CppString s = getXmlIndent(indent);
00672 s += ULXR_PCHAR("<value><boolean>");
00673
00674 if (val)
00675 s += ULXR_PCHAR("1");
00676 else
00677 s += ULXR_PCHAR("0");
00678
00679 s += ULXR_PCHAR("</boolean></value>");
00680 return s;
00681 }
00682
00683
00684 ULXR_API_IMPL(bool) Boolean::getBoolean () const
00685 {
00686 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00687 return val;
00688 }
00689
00690
00691 ULXR_API_IMPL(void) Boolean::setBoolean(const bool newval)
00692 {
00693 ULXR_ASSERT_RPCTYPE(RpcBoolean);
00694 val = newval;
00695 }
00696
00697
00699
00700
00701 ULXR_API_IMPL0 Integer::Integer ()
00702 : ValueBase(RpcInteger)
00703 {
00704 }
00705
00706
00707 ULXR_API_IMPL0 Integer::Integer (int i)
00708 : ValueBase(RpcInteger), val(i)
00709 {
00710 }
00711
00712
00713 ULXR_API_IMPL0 Integer::~Integer ()
00714 {
00715 }
00716
00717
00718 ULXR_API_IMPL0 Integer::Integer (const CppString &s)
00719 : ValueBase(RpcInteger)
00720 {
00721
00722 char *endp;
00723 val = strtol(getLatin1(s).c_str(), &endp, 10 );
00724
00725
00726 }
00727
00728
00729 ULXR_API_IMPL(ValueBase *) Integer::cloneValue() const
00730 {
00731 ULXR_ASSERT_RPCTYPE(RpcInteger);
00732 return new Integer(*this);
00733 }
00734
00735
00736
00737 ULXR_API_IMPL(CppString) Integer::getSignature(bool ) const
00738 {
00739 ULXR_ASSERT_RPCTYPE(RpcInteger);
00740 return getValueName();
00741 }
00742
00743
00744 ULXR_API_IMPL(CppString) Integer::getValueName()
00745 {
00746 return ULXR_PCHAR("int");
00747 }
00748
00749
00750 ULXR_API_IMPL(std::string) Integer::getWbXml() const
00751 {
00752 ULXR_ASSERT_RPCTYPE(RpcInteger);
00753 std::string s;
00754 s = (char)ValueParserWb::wbToken_Value;
00755 s += (char)ValueParserWb::wbToken_I4;
00756
00757 char buff[100];
00758 if (ulxr_snprintf(buff, sizeof(buff), "%d", val) >= (int) sizeof(buff))
00759 throw RuntimeException(ApplicationError,
00760 ulxr_i18n(ULXR_PCHAR("Buffer for conversion too small in Integer::getWbXml() ")));
00761
00762 s += getWbXmlString(ULXR_GET_STRING(buff));
00763 s += (char)WbXmlParser::wbxml_END;
00764 s += (char)WbXmlParser::wbxml_END;
00765 return s;
00766 }
00767
00768
00769 ULXR_API_IMPL(CppString) Integer::getXml(int indent) const
00770 {
00771 ULXR_ASSERT_RPCTYPE(RpcInteger);
00772 CppString s = getXmlIndent(indent);
00773 s += ULXR_PCHAR("<value><i4>");
00774
00775 char buff[100];
00776 if (ulxr_snprintf(buff, sizeof(buff), "%d", val) >= (int) sizeof(buff))
00777 throw RuntimeException(ApplicationError,
00778 ulxr_i18n(ULXR_PCHAR("Buffer for conversion too small in Integer::getXml() ")));
00779
00780 s += ULXR_GET_STRING(buff);
00781 s += ULXR_PCHAR("</i4></value>");
00782 return s;
00783 }
00784
00785
00786 ULXR_API_IMPL(int ) Integer::getInteger () const
00787 {
00788 ULXR_ASSERT_RPCTYPE(RpcInteger);
00789 return val;
00790 }
00791
00792
00793 ULXR_API_IMPL(void) Integer::setInteger(const int newval)
00794 {
00795 ULXR_ASSERT_RPCTYPE(RpcInteger);
00796 val = newval;
00797 }
00798
00799
00801
00802
00803 bool Double::scientific = false;
00804
00805
00806 ULXR_API_IMPL0 Double::Double ()
00807 : ValueBase(RpcDouble)
00808 {
00809 }
00810
00811
00812 ULXR_API_IMPL0 Double::Double (double d)
00813 : ValueBase(RpcDouble)
00814 , val(d)
00815 {
00816 }
00817
00818
00819 ULXR_API_IMPL0 Double::~Double ()
00820 {
00821 }
00822
00823
00824 ULXR_API_IMPL0 Double::Double (const CppString &s)
00825 : ValueBase(RpcDouble)
00826 {
00827 val = atof(getLatin1(s).c_str() );
00828 }
00829
00830
00831 ULXR_API_IMPL(ValueBase *) Double::cloneValue() const
00832 {
00833 ULXR_ASSERT_RPCTYPE(RpcDouble);
00834 return new Double(*this);
00835 }
00836
00837
00838 ULXR_API_IMPL(CppString) Double::getSignature(bool ) const
00839 {
00840 ULXR_ASSERT_RPCTYPE(RpcDouble);
00841 return getValueName();
00842 }
00843
00844
00845 ULXR_API_IMPL(CppString) Double::getValueName()
00846 {
00847 return ULXR_PCHAR("double");
00848 }
00849
00850
00851 ULXR_API_IMPL(bool) Double::setScientificMode(bool in_scientific)
00852 {
00853 bool prev = scientific;
00854 scientific = in_scientific;
00855 return prev;
00856 }
00857
00858
00859 ULXR_API_IMPL(std::string) Double::getWbXml() const
00860 {
00861 ULXR_ASSERT_RPCTYPE(RpcDouble);
00862 std::string s;
00863 char buff[1000];
00864
00865 unsigned used;
00866 if (scientific)
00867 used = ulxr_snprintf(buff, sizeof(buff), "%g", val);
00868 else
00869 used = ulxr_snprintf(buff, sizeof(buff), "%f", val);
00870
00871 if (used >= sizeof(buff))
00872 throw RuntimeException(ApplicationError,
00873 ulxr_i18n(ULXR_PCHAR("Buffer for conversion too small in Double::getWbXml ")));
00874
00875 s = ValueParserWb::wbToken_Value;
00876 s += ValueParserWb::wbToken_Double;
00877 s += getWbXmlString(ULXR_GET_STRING(buff));
00878 s += (char)WbXmlParser::wbxml_END;
00879 s += (char)WbXmlParser::wbxml_END;
00880 return s;
00881 }
00882
00883
00884 ULXR_API_IMPL(CppString) Double::getXml(int indent) const
00885 {
00886 ULXR_ASSERT_RPCTYPE(RpcDouble);
00887 CppString s = getXmlIndent(indent);
00888 s += ULXR_PCHAR("<value><double>");
00889 char buff[1000];
00890
00891 unsigned used;
00892 if (scientific)
00893 used = ulxr_snprintf(buff, sizeof(buff), "%g", val);
00894 else
00895 used = ulxr_snprintf(buff, sizeof(buff), "%f", val);
00896
00897 if (used >= sizeof(buff))
00898 throw RuntimeException(ApplicationError,
00899 ulxr_i18n(ULXR_PCHAR("Buffer for conversion too small in Double::getXml ")));
00900
00901 s += ULXR_GET_STRING(buff);
00902 s += ULXR_PCHAR("</double></value>");
00903 return s;
00904 }
00905
00906
00907 ULXR_API_IMPL(double) Double::getDouble () const
00908 {
00909 ULXR_ASSERT_RPCTYPE(RpcDouble);
00910 return val;
00911 }
00912
00913
00914 ULXR_API_IMPL(void) Double::setDouble(const double newval)
00915 {
00916 ULXR_ASSERT_RPCTYPE(RpcDouble);
00917 val = newval;
00918 }
00919
00920
00922
00923
00924 ULXR_API_IMPL0 RpcString::RpcString ()
00925 : ValueBase(RpcStrType)
00926 {
00927 }
00928
00929
00930 ULXR_API_IMPL0 RpcString::RpcString (const Cpp8BitString &s)
00931 : ValueBase(RpcStrType)
00932 {
00933 setString(s);
00934 }
00935
00936
00937 ULXR_API_IMPL0 RpcString::~RpcString ()
00938 {
00939 }
00940
00941
00942 #ifdef ULXR_UNICODE
00943
00944 ULXR_API_IMPL0 RpcString::RpcString (const Cpp16BitString &s)
00945 : ValueBase(RpcStrType)
00946 {
00947 setString(s);
00948 }
00949
00950 #endif
00951
00952 ULXR_API_IMPL(ValueBase *) RpcString::cloneValue() const
00953 {
00954 ULXR_ASSERT_RPCTYPE(RpcStrType);
00955 return new RpcString(*this);
00956 }
00957
00958
00959 ULXR_API_IMPL(CppString) RpcString::getSignature(bool ) const
00960 {
00961 ULXR_ASSERT_RPCTYPE(RpcStrType);
00962 return getValueName();
00963 }
00964
00965
00966 ULXR_API_IMPL(CppString) RpcString::getValueName()
00967 {
00968 return ULXR_PCHAR("string");
00969 }
00970
00971
00972 ULXR_API_IMPL(std::string) RpcString::getWbXml() const
00973 {
00974 ULXR_ASSERT_RPCTYPE(RpcStrType);
00975 std::string s;
00976 s = ValueParserWb::wbToken_Value;
00977 s += ValueParserWb::wbToken_String;
00978 s += getWbXmlString(val);
00979 s += (char)WbXmlParser::wbxml_END;
00980 s += (char)WbXmlParser::wbxml_END;
00981 return s;
00982 }
00983
00984
00985 ULXR_API_IMPL(CppString) RpcString::getXml(int indent) const
00986 {
00987 ULXR_ASSERT_RPCTYPE(RpcStrType);
00988 CppString s = getXmlIndent(indent);
00989 s += ULXR_PCHAR("<value><string>");
00990 s += xmlEscape(val);
00991 s += ULXR_PCHAR("</string></value>");
00992 return s;
00993 }
00994
00995
00996 ULXR_API_IMPL(CppString) RpcString::getString () const
00997 {
00998 ULXR_ASSERT_RPCTYPE(RpcStrType);
00999 return val;
01000 }
01001
01002
01003 #ifdef ULXR_UNICODE
01004
01005 ULXR_API_IMPL(Cpp16BitString) RpcString::getUnicodeString () const
01006 {
01007 ULXR_ASSERT_RPCTYPE(RpcStrType);
01008 #ifdef ULXR_UNICODE
01009 return val;
01010 #else
01011 return utf8ToUnicode(val);
01012 #endif
01013 }
01014
01015 #endif
01016
01017 #if (defined(HAVE_ICONV_H) || defined(HAVE_ICONV)) && !defined (ULXR_UNICODE)
01018
01019 ULXR_API_IMPL(CppString) RpcString::getString (const char *encoding) const
01020 {
01021 return utf8ToEncoding(val, encoding);
01022 }
01023
01024
01025 ULXR_API_IMPL(void) RpcString::setString(const Cpp8BitString &newval, const char *encoding)
01026 {
01027 val = encodingToUtf8(newval, encoding);
01028 }
01029
01030 #endif
01031
01032
01033 ULXR_API_IMPL(void) RpcString::setString(const Cpp8BitString &newval)
01034 {
01035 ULXR_ASSERT_RPCTYPE(RpcStrType);
01036 #ifdef ULXR_UNICODE
01037 val = getUnicode(newval);
01038 #else
01039 val = newval;
01040 #endif
01041 }
01042
01043
01044 #ifdef ULXR_UNICODE
01045
01046 ULXR_API_IMPL(void) RpcString::setString(const Cpp16BitString& newval)
01047 {
01048 ULXR_ASSERT_RPCTYPE(RpcStrType);
01049 val = newval;
01050 }
01051
01052 #endif
01053
01055
01056
01057 ULXR_API_IMPL0 Base64::Base64 ()
01058 : ValueBase(RpcBase64)
01059 {
01060 }
01061
01062
01063 ULXR_API_IMPL0 Base64::Base64 (const CppString &s)
01064 : ValueBase(RpcBase64)
01065 {
01066 setString(s);
01067 }
01068
01069
01070 ULXR_API_IMPL0 Base64::~Base64 ()
01071 {
01072 }
01073
01074
01075 ULXR_API_IMPL(CppString) Base64::getBase64() const
01076 {
01077 return val;
01078 }
01079
01080
01081 ULXR_API_IMPL(void) Base64::setBase64(const CppString s)
01082 {
01083 val = s;
01084 }
01085
01086
01087 ULXR_API_IMPL(ValueBase *) Base64::cloneValue() const
01088 {
01089 ULXR_ASSERT_RPCTYPE(RpcBase64);
01090 return new Base64(*this);
01091 }
01092
01093
01094 ULXR_API_IMPL(CppString) Base64::getSignature(bool ) const
01095 {
01096 ULXR_ASSERT_RPCTYPE(RpcBase64);
01097 return getValueName();
01098 }
01099
01100
01101 ULXR_API_IMPL(CppString) Base64::getValueName()
01102 {
01103 return ULXR_PCHAR("base64");
01104 }
01105
01106
01107 ULXR_API_IMPL(CppString) Base64::getXml(int indent) const
01108 {
01109 ULXR_ASSERT_RPCTYPE(RpcBase64);
01110 CppString s = getXmlIndent(indent);
01111 s += ULXR_PCHAR("<value><base64>");
01112 s += val;
01113 s += ULXR_PCHAR("</base64></value>");
01114 return s;
01115 }
01116
01117
01118 ULXR_API_IMPL(std::string) Base64::getWbXml() const
01119 {
01120 ULXR_ASSERT_RPCTYPE(RpcBase64);
01121 std::string s;
01122 s += ValueParserWb::wbToken_Value;
01123 s += ValueParserWb::wbToken_Base64;
01124 s += getWbXmlString(val);
01125 s += (char)WbXmlParser::wbxml_END;
01126 s += (char)WbXmlParser::wbxml_END;
01127 return s;
01128 }
01129
01130
01131 ULXR_API_IMPL(CppString) Base64::getString () const
01132 {
01133 ULXR_ASSERT_RPCTYPE(RpcBase64);
01134 return decodeBase64(val);
01135 }
01136
01137
01138 ULXR_API_IMPL(void) Base64::setString(const CppString &newval)
01139 {
01140 ULXR_ASSERT_RPCTYPE(RpcBase64);
01141 val = encodeBase64(newval);
01142 }
01143
01144
01146
01147
01148 ULXR_API_IMPL0 DateTime::DateTime ()
01149 : ValueBase(RpcDateTime)
01150 {
01151 }
01152
01153
01154 ULXR_API_IMPL0 DateTime::DateTime (const CppString &s)
01155 : ValueBase(RpcDateTime)
01156 , val(s)
01157 {
01158 }
01159
01160
01161 ULXR_API_IMPL0 DateTime::DateTime (const ulxr_time_t &tm)
01162 : ValueBase(RpcDateTime)
01163 {
01164 setDateTime(tm);
01165 }
01166
01167
01168 ULXR_API_IMPL0 DateTime::~DateTime ()
01169 {
01170 }
01171
01172
01173 ULXR_API_IMPL(ValueBase *) DateTime::cloneValue() const
01174 {
01175 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01176 return new DateTime(*this);
01177 }
01178
01179
01180 ULXR_API_IMPL(CppString) DateTime::getSignature(bool ) const
01181 {
01182 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01183 return getValueName();
01184 }
01185
01186
01187 ULXR_API_IMPL(CppString) DateTime::getValueName()
01188 {
01189 return ULXR_PCHAR("dateTime.iso8601");
01190 }
01191
01192
01193 ULXR_API_IMPL(std::string) DateTime::getWbXml() const
01194 {
01195 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01196 std::string s;
01197 s += ValueParserWb::wbToken_Value;
01198 s += ValueParserWb::wbToken_Date;
01199 s += getWbXmlString(val);
01200 s += (char)WbXmlParser::wbxml_END;
01201 s += (char)WbXmlParser::wbxml_END;
01202 return s;
01203 }
01204
01205
01206 ULXR_API_IMPL(CppString) DateTime::getXml(int indent) const
01207 {
01208 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01209 CppString s = getXmlIndent(indent);
01210 s += ULXR_PCHAR("<value><dateTime.iso8601>");
01211 s += val;
01212 s += ULXR_PCHAR("</dateTime.iso8601></value>");
01213 return s;
01214 }
01215
01216
01217 ULXR_API_IMPL(CppString) DateTime::getDateTime () const
01218 {
01219 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01220 return val;
01221 }
01222
01223
01224 namespace {
01225
01226 static CppString padded(unsigned num)
01227 {
01228 CppString s;
01229 if (num < 10)
01230 s += L'0';
01231 s += HtmlFormHandler::makeNumber(num);
01232 return s;
01233 }
01234
01235 }
01236
01237
01238 ULXR_API_IMPL(void) DateTime::setDateTime (const ulxr_time_t &tmt,
01239 bool add_dash ,
01240 bool add_colon )
01241 {
01242 #ifndef ULXR_OMIT_REENTRANT_PROTECTOR
01243 Mutex::Locker lock(localtimeMutex);
01244 #endif
01245
01246 CppString s;
01247 ulxr_tm * ltm = ulxr_localtime(&tmt);
01248 s += padded(ltm->tm_year+1900);
01249 if (add_dash)
01250 s += '-';
01251 s += padded(ltm->tm_mon+1);
01252 if (add_dash)
01253 s += '-';
01254 s += padded(ltm->tm_mday);
01255 s += ULXR_PCHAR("T");
01256 s += padded(ltm->tm_hour);
01257 if (add_colon)
01258 s += ':';
01259 s += padded(ltm->tm_min);
01260 if (add_colon)
01261 s += ':';
01262 s += padded(ltm->tm_sec);
01263 setDateTime(s);
01264 }
01265
01266
01267 ULXR_API_IMPL(void) DateTime::setDateTime(const CppString &newval)
01268 {
01269 ULXR_ASSERT_RPCTYPE(RpcDateTime);
01270 val = newval;
01271 }
01272
01273
01275
01276
01277 ULXR_API_IMPL0 Array::Array ()
01278 : ValueBase(RpcArray)
01279 {
01280 }
01281
01282
01283 ULXR_API_IMPL0 Array::~Array ()
01284 {
01285 }
01286
01287
01288 ULXR_API_IMPL(unsigned) Array::size() const
01289 {
01290 return values.size();
01291 }
01292
01293
01294 ULXR_API_IMPL(void) Array::clear()
01295 {
01296 values.clear();
01297 }
01298
01299
01300 ULXR_API_IMPL(ValueBase *) Array::cloneValue() const
01301 {
01302 ULXR_ASSERT_RPCTYPE(RpcArray);
01303 return new Array(*this);
01304 }
01305
01306
01307 ULXR_API_IMPL(CppString) Array::getSignature(bool deep) const
01308 {
01309 if (!deep)
01310 return getValueName();
01311
01312
01313 ULXR_ASSERT_RPCTYPE(RpcArray);
01314 CppString s;
01315 if (values.size() == 0)
01316 return ULXR_PCHAR("[]");
01317
01318 s += ULXR_CHAR('[');
01319 bool comma = values.size() >= 1;
01320 for (unsigned i = 0; i < values.size(); ++i)
01321 {
01322 if (comma && i != 0)
01323 s += ULXR_CHAR(',');
01324 s += values[i].getSignature();
01325 }
01326 s += ULXR_CHAR(']');
01327
01328 return s;
01329 }
01330
01331
01332 ULXR_API_IMPL(CppString) Array::getValueName()
01333 {
01334 return ULXR_PCHAR("array");
01335 }
01336
01337
01338 ULXR_API_IMPL(std::string) Array::getWbXml() const
01339 {
01340 ULXR_ASSERT_RPCTYPE(RpcArray);
01341 std::string s;
01342 s = ValueParserWb::wbToken_Value;
01343 s += ValueParserWb::wbToken_Array;
01344 s += ValueParserWb::wbToken_Data;
01345
01346 for (std::vector<Value>::const_iterator
01347 it = values.begin(); it != values.end(); ++it)
01348 {
01349 s += (*it).getWbXml();
01350 }
01351
01352 s += WbXmlParser::wbxml_END;
01353 s += WbXmlParser::wbxml_END;
01354 s += WbXmlParser::wbxml_END;
01355 return s;
01356 }
01357
01358
01359 ULXR_API_IMPL(CppString) Array::getXml(int indent) const
01360 {
01361 ULXR_ASSERT_RPCTYPE(RpcArray);
01362 CppString ind = getXmlIndent(indent);
01363 CppString ind1 = getXmlIndent(indent+1);
01364 CppString ind2 = getXmlIndent(indent+2);
01365 CppString s = ind + ULXR_PCHAR("<value>");
01366 s += ind1 + ULXR_PCHAR("<array>") + getXmlLinefeed();
01367 s += ind2 + ULXR_PCHAR("<data>") + getXmlLinefeed();
01368
01369 for (std::vector<Value>::const_iterator
01370 it = values.begin(); it != values.end(); ++it)
01371 {
01372 s += (*it).getXml(indent+3) + getXmlLinefeed();
01373 }
01374
01375 s += ind2 + ULXR_PCHAR("</data>") + getXmlLinefeed();
01376 s += ind1 + ULXR_PCHAR("</array>")+ getXmlLinefeed();
01377 s += ind + ULXR_PCHAR("</value>");
01378 return s;
01379 }
01380
01381
01382 ULXR_API_IMPL(void) Array::addItem(const Value &item)
01383 {
01384 values.push_back(item);
01385 }
01386
01387
01388 ULXR_API_IMPL(void) Array::setItem(unsigned idx, const Value &item)
01389 {
01390 if (idx < values.size() )
01391 values[idx] = item;
01392 }
01393
01394
01395 ULXR_API_IMPL(Value) Array::getItem(unsigned idx)
01396 {
01397 if (idx < values.size() )
01398 return values[idx];
01399 else
01400 return Value(RpcString());
01401 }
01402
01403
01405
01406
01407 ULXR_API_IMPL0 Struct::Member::Member(const CppString &str_, const Value &t_)
01408 : str(str_)
01409 , t(t_)
01410 {
01411 }
01412
01413
01414 const CppString & Struct::Member::getName() const
01415 {
01416 return str;
01417 }
01418
01419
01420 const Value & Struct::Member::getValue() const
01421 {
01422 return t;
01423 }
01424
01425
01427
01428
01429 ULXR_API_IMPL0 Struct::Struct ()
01430 : ValueBase(RpcStruct)
01431 {
01432 }
01433
01434
01435 ULXR_API_IMPL0 Struct::~Struct ()
01436 {
01437 }
01438
01439
01440 ULXR_API_IMPL(ValueBase *) Struct::cloneValue() const
01441 {
01442 ULXR_ASSERT_RPCTYPE(RpcStruct);
01443 return new Struct(*this);
01444 }
01445
01446
01447 ULXR_API_IMPL(void) Struct::clear()
01448 {
01449 val.clear();
01450 }
01451
01452
01453 ULXR_API_IMPL(unsigned) Struct::size() const
01454 {
01455 return val.size() ;
01456 }
01457
01458
01459 ULXR_API_IMPL(const Struct::Members&) Struct::getAllMembers() const
01460 {
01461 return val;
01462 }
01463
01464
01465 ULXR_API_IMPL(CppString) Struct::getSignature(bool deep) const
01466 {
01467 if (!deep)
01468 return getValueName();
01469
01470 ULXR_ASSERT_RPCTYPE(RpcStruct);
01471 CppString s;
01472 if (val.size() == 0)
01473 return ULXR_PCHAR("{}");
01474
01475 if (val.size() > 1)
01476 s += ULXR_CHAR('{');
01477
01478 for (Members::const_iterator it = val.begin(); it != val.end(); ++it)
01479 {
01480 s += ULXR_CHAR('{');
01481 s += (*it).first;
01482 s += ULXR_CHAR(',');
01483 s += (*it).second.getSignature();
01484 s += ULXR_CHAR('}');
01485 }
01486
01487 if (val.size() > 1)
01488 s += ULXR_CHAR('}');
01489
01490 return s;
01491 }
01492
01493
01494 ULXR_API_IMPL(CppString) Struct::getValueName()
01495 {
01496 return ULXR_PCHAR("struct");
01497 }
01498
01499
01500 ULXR_API_IMPL(CppString) Struct::getXml(int indent) const
01501 {
01502 ULXR_ASSERT_RPCTYPE(RpcStruct);
01503 CppString ind = getXmlIndent(indent);
01504 CppString ind1 = getXmlIndent(indent+1);
01505 CppString ind2 = getXmlIndent(indent+2);
01506 CppString ind3 = getXmlIndent(indent+3);
01507 CppString s = ind + ULXR_PCHAR("<value>")+ getXmlLinefeed();
01508 s += ind1 + ULXR_PCHAR("<struct>") + getXmlLinefeed();
01509
01510 for (Members::const_iterator it = val.begin(); it != val.end(); ++it)
01511 {
01512 s += ind2 + ULXR_PCHAR("<member>") + getXmlLinefeed();
01513 s += ind3 + ULXR_PCHAR("<name>") + (*it).first + ULXR_PCHAR("</name>") + getXmlLinefeed();
01514 s += (*it).second.getXml(indent+3) + getXmlLinefeed();
01515 s += ind2 + ULXR_PCHAR("</member>") + getXmlLinefeed();
01516 }
01517
01518 s += ind1 + ULXR_PCHAR("</struct>") + getXmlLinefeed();
01519 s += ind + ULXR_PCHAR("</value>");
01520 return s;
01521 }
01522
01523
01524 ULXR_API_IMPL(std::string) Struct::getWbXml() const
01525 {
01526 ULXR_ASSERT_RPCTYPE(RpcStruct);
01527 std::string s;
01528 s = ValueParserWb::wbToken_Value;
01529 s += ValueParserWb::wbToken_Struct;
01530
01531 for (Members::const_iterator it = val.begin(); it != val.end(); ++it)
01532 {
01533 s += ValueParserWb::wbToken_Member;
01534 s += ValueParserWb::wbToken_Name;
01535 s += getWbXmlString((*it).first);
01536 s += (char)WbXmlParser::wbxml_END;
01537 s += (*it).second.getWbXml();
01538 s += (char)WbXmlParser::wbxml_END;
01539 }
01540
01541 s += WbXmlParser::wbxml_END;
01542 s += WbXmlParser::wbxml_END;
01543 return s;
01544 }
01545
01546
01547 ULXR_API_IMPL(void) Struct::addMember(const CppString &name, const Value &item)
01548 {
01549 ULXR_TRACE("Struct::addMember(string, Value)");
01550 ULXR_ASSERT_RPCTYPE(RpcStruct);
01551 val.insert(Member_pair(name, item));
01552 }
01553
01554
01555 ULXR_API_IMPL(bool) Struct::hasMember(const CppString &name) const
01556 {
01557 ULXR_ASSERT_RPCTYPE(RpcStruct);
01558 return val.find(name) != val.end();
01559 }
01560
01561
01562 ULXR_API_IMPL(Value) Struct::getMember(const CppString &name) const
01563 {
01564 ULXR_ASSERT_RPCTYPE(RpcStruct);
01565 Members::const_iterator it = val.find(name);
01566 if (it == val.end())
01567 throw RuntimeException(ApplicationError,
01568 ulxr_i18n(ULXR_PCHAR("Attempt to get unknown Struct member: ")) +name);
01569
01570 return (*it).second;
01571 }
01572
01573
01574 ULXR_API_IMPL(std::vector<CppString>) Struct::getMemberNames() const
01575 {
01576 std::vector<CppString> names;
01577 for (Members::const_iterator it = val.begin(); it != val.end(); ++it)
01578 names.push_back((*it).first);
01579 return names;
01580 }
01581
01582
01583 #ifdef ULXR_STRUCT_MEMBER_FROM_NAME_VALUE
01584
01585 ULXR_API_IMPL(Struct::Member) operator<< (const CppString &str, const Value &t)
01586 {
01587 ULXR_TRACE("Struct::Member operator<< (string, T)");
01588 return Struct::Member(str, t);
01589 }
01590
01591 #endif
01592
01593 ULXR_API_IMPL(Struct::Member) make_member (const CppString &str, const Value &t)
01594 {
01595 ULXR_TRACE(ULXR_PCHAR("Member operator<< (string, T)"));
01596 return Struct::Member(str, t);
01597 }
01598
01599
01600 ULXR_API_IMPL(Struct) & operator<< (Struct &st, const Struct::Member &k)
01601 {
01602 ULXR_TRACE(ULXR_PCHAR("operator<<(Struct, Struct::Member)"));
01603 st.addMember(k.getName(), k.getValue());
01604 return st;
01605 }
01606
01607
01608 };
01609