Var.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  1. //
  2. // Var.h
  3. //
  4. // Library: Foundation
  5. // Package: Dynamic
  6. // Module: Var
  7. //
  8. // Definition of the Var class.
  9. //
  10. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_Var_INCLUDED
  16. #define Foundation_Var_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/Format.h"
  19. #include "Poco/SharedPtr.h"
  20. #include "Poco/Dynamic/VarHolder.h"
  21. #include "Poco/Dynamic/VarIterator.h"
  22. #include <typeinfo>
  23. namespace Poco {
  24. namespace Dynamic {
  25. template <typename T>
  26. class Struct;
  27. class Foundation_API Var
  28. /// Var allows to store data of different types and to convert between these types transparently.
  29. /// Var puts forth the best effort to provide intuitive and reasonable conversion semantics and prevent
  30. /// unexpected data loss, particularly when performing narrowing or signedness conversions of numeric data types.
  31. ///
  32. /// An attempt to convert or extract from a non-initialized ("empty") Var variable shall result
  33. /// in an exception being thrown.
  34. ///
  35. /// Loss of signedness is not allowed for numeric values. This means that if an attempt is made to convert
  36. /// the internal value which is a negative signed integer to an unsigned integer type storage, a RangeException is thrown.
  37. /// Overflow is not allowed, so if the internal value is a larger number than the target numeric type size can accommodate,
  38. /// a RangeException is thrown.
  39. ///
  40. /// Precision loss, such as in conversion from floating-point types to integers or from double to float on platforms
  41. /// where they differ in size (provided internal actual value fits in float min/max range), is allowed.
  42. ///
  43. /// String truncation is allowed -- it is possible to convert between string and character when string length is
  44. /// greater than 1. An empty string gets converted to the char '\0', a non-empty string is truncated to the first character.
  45. ///
  46. /// Boolean conversion is performed as follows:
  47. ///
  48. /// A string value "false" (not case sensitive), "0" or "" (empty string) can be converted to a boolean value false,
  49. /// any other string not being false by the above criteria evaluates to true (e.g: "hi" -> true).
  50. /// Integer 0 values are false, everything else is true.
  51. /// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true.
  52. ///
  53. /// Arithmetic operations with POD types as well as between Var's are supported, subject to following
  54. /// limitations:
  55. ///
  56. /// - for std::string and const char* values, only '+' and '+=' operations are supported
  57. ///
  58. /// - for integral and floating point numeric values, following operations are supported:
  59. /// '+', '+=', '-', '-=', '*', '*=' , '/' and '/='
  60. ///
  61. /// - for integral values, following operations are supported:
  62. /// prefix and postfix increment (++) and decrement (--)
  63. ///
  64. /// - for all other types, InvalidArgumentException is thrown upon attempt of an arithmetic operation
  65. ///
  66. /// A Var can be created from and converted to a value of any type for which a specialization of
  67. /// VarHolderImpl is available. For supported types, see VarHolder documentation.
  68. {
  69. public:
  70. typedef SharedPtr<Var> Ptr;
  71. typedef Poco::Dynamic::VarIterator Iterator;
  72. typedef const VarIterator ConstIterator;
  73. Var();
  74. /// Creates an empty Var.
  75. template <typename T>
  76. Var(const T& val)
  77. /// Creates the Var from the given value.
  78. #ifdef POCO_NO_SOO
  79. : _pHolder(new VarHolderImpl<T>(val))
  80. {
  81. }
  82. #else
  83. {
  84. construct(val);
  85. }
  86. #endif
  87. Var(const char* pVal);
  88. // Convenience constructor for const char* which gets mapped to a std::string internally, i.e. pVal is deep-copied.
  89. Var(const Var& other);
  90. /// Copy constructor.
  91. ~Var();
  92. /// Destroys the Var.
  93. void swap(Var& other);
  94. /// Swaps the content of the this Var with the other Var.
  95. ConstIterator begin() const;
  96. /// Returns the const Var iterator.
  97. ConstIterator end() const;
  98. /// Returns the const Var iterator.
  99. Iterator begin();
  100. /// Returns the Var iterator.
  101. Iterator end();
  102. /// Returns the Var iterator.
  103. template <typename T>
  104. void convert(T& val) const
  105. /// Invoke this method to perform a safe conversion.
  106. ///
  107. /// Example usage:
  108. /// Var any("42");
  109. /// int i;
  110. /// any.convert(i);
  111. ///
  112. /// Throws a RangeException if the value does not fit
  113. /// into the result variable.
  114. /// Throws a NotImplementedException if conversion is
  115. /// not available for the given type.
  116. /// Throws InvalidAccessException if Var is empty.
  117. {
  118. VarHolder* pHolder = content();
  119. if (!pHolder)
  120. throw InvalidAccessException("Can not convert empty value.");
  121. pHolder->convert(val);
  122. }
  123. template <typename T>
  124. T convert() const
  125. /// Invoke this method to perform a safe conversion.
  126. ///
  127. /// Example usage:
  128. /// Var any("42");
  129. /// int i = any.convert<int>();
  130. ///
  131. /// Throws a RangeException if the value does not fit
  132. /// into the result variable.
  133. /// Throws a NotImplementedException if conversion is
  134. /// not available for the given type.
  135. /// Throws InvalidAccessException if Var is empty.
  136. {
  137. VarHolder* pHolder = content();
  138. if (!pHolder)
  139. throw InvalidAccessException("Can not convert empty value.");
  140. if (typeid(T) == pHolder->type()) return extract<T>();
  141. T result;
  142. pHolder->convert(result);
  143. return result;
  144. }
  145. template <typename T>
  146. operator T () const
  147. /// Safe conversion operator for implicit type
  148. /// conversions. If the requested type T is same as the
  149. /// type being held, the operation performed is direct
  150. /// extraction, otherwise it is the conversion of the value
  151. /// from type currently held to the one requested.
  152. ///
  153. /// Throws a RangeException if the value does not fit
  154. /// into the result variable.
  155. /// Throws a NotImplementedException if conversion is
  156. /// not available for the given type.
  157. /// Throws InvalidAccessException if Var is empty.
  158. {
  159. VarHolder* pHolder = content();
  160. if (!pHolder)
  161. throw InvalidAccessException("Can not convert empty value.");
  162. if (typeid(T) == pHolder->type())
  163. return extract<T>();
  164. else
  165. {
  166. T result;
  167. pHolder->convert(result);
  168. return result;
  169. }
  170. }
  171. template <typename T>
  172. const T& extract() const
  173. /// Returns a const reference to the actual value.
  174. ///
  175. /// Must be instantiated with the exact type of
  176. /// the stored value, otherwise a BadCastException
  177. /// is thrown.
  178. /// Throws InvalidAccessException if Var is empty.
  179. {
  180. VarHolder* pHolder = content();
  181. if (pHolder && pHolder->type() == typeid(T))
  182. {
  183. VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
  184. return pHolderImpl->value();
  185. }
  186. else if (!pHolder)
  187. throw InvalidAccessException("Can not extract empty value.");
  188. else
  189. throw BadCastException(format("Can not convert %s to %s.",
  190. std::string(pHolder->type().name()),
  191. std::string(typeid(T).name())));
  192. }
  193. template <typename T>
  194. Var& operator = (const T& other)
  195. /// Assignment operator for assigning POD to Var
  196. {
  197. #ifdef POCO_NO_SOO
  198. Var tmp(other);
  199. swap(tmp);
  200. #else
  201. construct(other);
  202. #endif
  203. return *this;
  204. }
  205. bool operator ! () const;
  206. /// Logical NOT operator.
  207. Var& operator = (const Var& other);
  208. /// Assignment operator specialization for Var
  209. template <typename T>
  210. const Var operator + (const T& other) const
  211. /// Addition operator for adding POD to Var
  212. {
  213. return convert<T>() + other;
  214. }
  215. const Var operator + (const Var& other) const;
  216. /// Addition operator specialization for Var
  217. const Var operator + (const char* other) const;
  218. /// Addition operator specialization for adding const char* to Var
  219. Var& operator ++ ();
  220. /// Pre-increment operator
  221. const Var operator ++ (int);
  222. /// Post-increment operator
  223. Var& operator -- ();
  224. /// Pre-decrement operator
  225. const Var operator -- (int);
  226. /// Post-decrement operator
  227. template <typename T>
  228. Var& operator += (const T& other)
  229. /// Addition assignment operator for addition/assignment of POD to Var.
  230. {
  231. return *this = convert<T>() + other;
  232. }
  233. Var& operator += (const Var& other);
  234. /// Addition assignment operator overload for Var
  235. Var& operator += (const char* other);
  236. /// Addition assignment operator overload for const char*
  237. template <typename T>
  238. const Var operator - (const T& other) const
  239. /// Subtraction operator for subtracting POD from Var
  240. {
  241. return convert<T>() - other;
  242. }
  243. const Var operator - (const Var& other) const;
  244. /// Subtraction operator overload for Var
  245. template <typename T>
  246. Var& operator -= (const T& other)
  247. /// Subtraction assignment operator
  248. {
  249. return *this = convert<T>() - other;
  250. }
  251. Var& operator -= (const Var& other);
  252. /// Subtraction assignment operator overload for Var
  253. template <typename T>
  254. const Var operator * (const T& other) const
  255. /// Multiplication operator for multiplying Var with POD
  256. {
  257. return convert<T>() * other;
  258. }
  259. const Var operator * (const Var& other) const;
  260. /// Multiplication operator overload for Var
  261. template <typename T>
  262. Var& operator *= (const T& other)
  263. /// Multiplication assignment operator
  264. {
  265. return *this = convert<T>() * other;
  266. }
  267. Var& operator *= (const Var& other);
  268. /// Multiplication assignment operator overload for Var
  269. template <typename T>
  270. const Var operator / (const T& other) const
  271. /// Division operator for dividing Var with POD
  272. {
  273. return convert<T>() / other;
  274. }
  275. const Var operator / (const Var& other) const;
  276. /// Division operator overload for Var
  277. template <typename T>
  278. Var& operator /= (const T& other)
  279. /// Division assignment operator
  280. {
  281. return *this = convert<T>() / other;
  282. }
  283. Var& operator /= (const Var& other);
  284. /// Division assignment operator specialization for Var
  285. template <typename T>
  286. bool operator == (const T& other) const
  287. /// Equality operator
  288. {
  289. if (isEmpty()) return false;
  290. return convert<T>() == other;
  291. }
  292. bool operator == (const char* other) const;
  293. /// Equality operator overload for const char*
  294. bool operator == (const Var& other) const;
  295. /// Equality operator overload for Var
  296. template <typename T>
  297. bool operator != (const T& other) const
  298. /// Inequality operator
  299. {
  300. if (isEmpty()) return true;
  301. return convert<T>() != other;
  302. }
  303. bool operator != (const Var& other) const;
  304. /// Inequality operator overload for Var
  305. bool operator != (const char* other) const;
  306. /// Inequality operator overload for const char*
  307. template <typename T>
  308. bool operator < (const T& other) const
  309. /// Less than operator
  310. {
  311. if (isEmpty()) return false;
  312. return convert<T>() < other;
  313. }
  314. bool operator < (const Var& other) const;
  315. /// Less than operator overload for Var
  316. template <typename T>
  317. bool operator <= (const T& other) const
  318. /// Less than or equal operator
  319. {
  320. if (isEmpty()) return false;
  321. return convert<T>() <= other;
  322. }
  323. bool operator <= (const Var& other) const;
  324. /// Less than or equal operator overload for Var
  325. template <typename T>
  326. bool operator > (const T& other) const
  327. /// Greater than operator
  328. {
  329. if (isEmpty()) return false;
  330. return convert<T>() > other;
  331. }
  332. bool operator > (const Var& other) const;
  333. /// Greater than operator overload for Var
  334. template <typename T>
  335. bool operator >= (const T& other) const
  336. /// Greater than or equal operator
  337. {
  338. if (isEmpty()) return false;
  339. return convert<T>() >= other;
  340. }
  341. bool operator >= (const Var& other) const;
  342. /// Greater than or equal operator overload for Var
  343. template <typename T>
  344. bool operator || (const T& other) const
  345. /// Logical OR operator
  346. {
  347. if (isEmpty()) return false;
  348. return convert<bool>() || other;
  349. }
  350. bool operator || (const Var& other) const;
  351. /// Logical OR operator operator overload for Var
  352. template <typename T>
  353. bool operator && (const T& other) const
  354. /// Logical AND operator.
  355. {
  356. if (isEmpty()) return false;
  357. return convert<bool>() && other;
  358. }
  359. bool operator && (const Var& other) const;
  360. /// Logical AND operator operator overload for Var.
  361. bool isArray() const;
  362. /// Returns true if Var is an array.
  363. bool isVector() const;
  364. /// Returns true if Var represents a vector.
  365. bool isList() const;
  366. /// Returns true if Var represents a list.
  367. bool isDeque() const;
  368. /// Returns true if Var represents a deque.
  369. bool isStruct() const;
  370. /// Returns true if Var represents a struct.
  371. char& at(std::size_t n);
  372. /// Returns character at position n. This function only works with
  373. /// Var containing a std::string.
  374. template <typename T>
  375. Var& operator [] (const T& n)
  376. {
  377. return getAt(n);
  378. }
  379. template <typename T>
  380. const Var& operator [] (const T& n) const
  381. {
  382. return const_cast<Var*>(this)->getAt(n);
  383. }
  384. Var& operator [] (const std::string& name);
  385. /// Index operator by name, only use on Vars where isStruct
  386. /// returns true! In all other cases InvalidAccessException is thrown.
  387. const Var& operator [] (const std::string& name) const;
  388. /// Index operator by name, only use on Vars where isStruct
  389. /// returns true! In all other cases InvalidAccessException is thrown.
  390. const std::type_info& type() const;
  391. /// Returns the type information of the stored content.
  392. //@ deprecated
  393. void empty();
  394. /// Empties Var.
  395. /// This function is deprecated and will be removed.
  396. /// Please use clear().
  397. void clear();
  398. /// Empties Var.
  399. bool isEmpty() const;
  400. /// Returns true if empty.
  401. bool isInteger() const;
  402. /// Returns true if stored value is integer.
  403. bool isSigned() const;
  404. /// Returns true if stored value is signed.
  405. bool isNumeric() const;
  406. /// Returns true if stored value is numeric.
  407. /// Returns false for numeric strings (e.g. "123" is string, not number)
  408. bool isBoolean() const;
  409. /// Returns true if stored value is boolean.
  410. /// Returns false for boolean strings (e.g. "true" is string, not number)
  411. bool isString() const;
  412. /// Returns true if stored value is std::string.
  413. bool isDate() const;
  414. /// Returns true if stored value represents a date.
  415. bool isTime() const;
  416. /// Returns true if stored value represents time or date/time.
  417. bool isDateTime() const;
  418. /// Returns true if stored value represents a date/time.
  419. std::size_t size() const;
  420. /// Returns the size of this Var.
  421. /// This function returns 0 when Var is empty, 1 for POD or the size (i.e. length)
  422. /// for held container.
  423. std::string toString() const
  424. /// Returns the stored value as string.
  425. {
  426. VarHolder* pHolder = content();
  427. if (!pHolder)
  428. throw InvalidAccessException("Can not convert empty value.");
  429. if (typeid(std::string) == pHolder->type())
  430. return extract<std::string>();
  431. else
  432. {
  433. std::string result;
  434. pHolder->convert(result);
  435. return result;
  436. }
  437. }
  438. static Var parse(const std::string& val);
  439. /// Parses the string which must be in JSON format
  440. static std::string toString(const Var& var);
  441. /// Converts the Var to a string in JSON format. Note that toString(const Var&) will return
  442. /// a different result than Var::convert<std::string>() and Var::toString()!
  443. private:
  444. Var& getAt(std::size_t n);
  445. Var& getAt(const std::string& n);
  446. static Var parse(const std::string& val, std::string::size_type& offset);
  447. /// Parses the string which must be in JSON format
  448. static Var parseObject(const std::string& val, std::string::size_type& pos);
  449. static Var parseArray(const std::string& val, std::string::size_type& pos);
  450. static std::string parseString(const std::string& val, std::string::size_type& pos);
  451. static std::string parseJSONString(const std::string& val, std::string::size_type& pos);
  452. static void skipWhiteSpace(const std::string& val, std::string::size_type& pos);
  453. template <typename T>
  454. T add(const Var& other) const
  455. {
  456. return convert<T>() + other.convert<T>();
  457. }
  458. template <typename T>
  459. T subtract(const Var& other) const
  460. {
  461. return convert<T>() - other.convert<T>();
  462. }
  463. template <typename T>
  464. T multiply(const Var& other) const
  465. {
  466. return convert<T>() * other.convert<T>();
  467. }
  468. template <typename T>
  469. T divide(const Var& other) const
  470. {
  471. return convert<T>() / other.convert<T>();
  472. }
  473. template <typename T, typename E>
  474. VarHolderImpl<T>* holderImpl(const std::string errorMessage = "") const
  475. {
  476. VarHolder* pHolder = content();
  477. if (pHolder && pHolder->type() == typeid(T))
  478. return static_cast<VarHolderImpl<T>*>(pHolder);
  479. else if (!pHolder)
  480. throw InvalidAccessException("Can not access empty value.");
  481. else
  482. throw E(errorMessage);
  483. }
  484. Var& structIndexOperator(VarHolderImpl<Struct<int> >* pStr, int n) const;
  485. #ifdef POCO_NO_SOO
  486. VarHolder* content() const
  487. {
  488. return _pHolder;
  489. }
  490. void destruct()
  491. {
  492. if (!isEmpty()) delete content();
  493. }
  494. VarHolder* _pHolder;
  495. #else
  496. VarHolder* content() const
  497. {
  498. return _placeholder.content();
  499. }
  500. template<typename ValueType>
  501. void construct(const ValueType& value)
  502. {
  503. if (sizeof(VarHolderImpl<ValueType>) <= Placeholder<ValueType>::Size::value)
  504. {
  505. new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<ValueType>(value);
  506. _placeholder.setLocal(true);
  507. }
  508. else
  509. {
  510. _placeholder.pHolder = new VarHolderImpl<ValueType>(value);
  511. _placeholder.setLocal(false);
  512. }
  513. }
  514. void construct(const char* value)
  515. {
  516. std::string val(value);
  517. if (sizeof(VarHolderImpl<std::string>) <= Placeholder<std::string>::Size::value)
  518. {
  519. new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<std::string>(val);
  520. _placeholder.setLocal(true);
  521. }
  522. else
  523. {
  524. _placeholder.pHolder = new VarHolderImpl<std::string>(val);
  525. _placeholder.setLocal(false);
  526. }
  527. }
  528. void construct(const Var& other)
  529. {
  530. if (!other.isEmpty())
  531. other.content()->clone(&_placeholder);
  532. else
  533. _placeholder.erase();
  534. }
  535. void destruct()
  536. {
  537. if (!isEmpty())
  538. {
  539. if (_placeholder.isLocal())
  540. content()->~VarHolder();
  541. else
  542. delete content();
  543. }
  544. }
  545. Placeholder<VarHolder> _placeholder;
  546. #endif // POCO_NO_SOO
  547. };
  548. ///
  549. /// inlines
  550. ///
  551. ///
  552. /// Var members
  553. ///
  554. inline void Var::swap(Var& other)
  555. {
  556. #ifdef POCO_NO_SOO
  557. std::swap(_pHolder, other._pHolder);
  558. #else
  559. if (this == &other) return;
  560. if (!_placeholder.isLocal() && !other._placeholder.isLocal())
  561. {
  562. std::swap(_placeholder.pHolder, other._placeholder.pHolder);
  563. }
  564. else
  565. {
  566. Var tmp(*this);
  567. try
  568. {
  569. if (_placeholder.isLocal()) destruct();
  570. construct(other);
  571. other = tmp;
  572. }
  573. catch (...)
  574. {
  575. construct(tmp);
  576. throw;
  577. }
  578. }
  579. #endif
  580. }
  581. inline const std::type_info& Var::type() const
  582. {
  583. VarHolder* pHolder = content();
  584. return pHolder ? pHolder->type() : typeid(void);
  585. }
  586. inline Var::ConstIterator Var::begin() const
  587. {
  588. if (isEmpty()) return ConstIterator(const_cast<Var*>(this), true);
  589. return ConstIterator(const_cast<Var*>(this), false);
  590. }
  591. inline Var::ConstIterator Var::end() const
  592. {
  593. return ConstIterator(const_cast<Var*>(this), true);
  594. }
  595. inline Var::Iterator Var::begin()
  596. {
  597. if (isEmpty()) return Iterator(const_cast<Var*>(this), true);
  598. return Iterator(const_cast<Var*>(this), false);
  599. }
  600. inline Var::Iterator Var::end()
  601. {
  602. return Iterator(this, true);
  603. }
  604. inline Var& Var::operator [] (const std::string& name)
  605. {
  606. return getAt(name);
  607. }
  608. inline const Var& Var::operator [] (const std::string& name) const
  609. {
  610. return const_cast<Var*>(this)->getAt(name);
  611. }
  612. inline const Var Var::operator + (const char* other) const
  613. {
  614. return convert<std::string>() + other;
  615. }
  616. inline Var& Var::operator += (const char*other)
  617. {
  618. return *this = convert<std::string>() + other;
  619. }
  620. inline bool Var::operator ! () const
  621. {
  622. return !convert<bool>();
  623. }
  624. inline bool Var::isEmpty() const
  625. {
  626. return 0 == content();
  627. }
  628. inline bool Var::isArray() const
  629. {
  630. if (isEmpty() ||
  631. isString()) return false;
  632. VarHolder* pHolder = content();
  633. return pHolder ? pHolder->isArray() : false;
  634. }
  635. inline bool Var::isVector() const
  636. {
  637. VarHolder* pHolder = content();
  638. return pHolder ? pHolder->isVector() : false;
  639. }
  640. inline bool Var::isList() const
  641. {
  642. VarHolder* pHolder = content();
  643. return pHolder ? pHolder->isList() : false;
  644. }
  645. inline bool Var::isDeque() const
  646. {
  647. VarHolder* pHolder = content();
  648. return pHolder ? pHolder->isDeque() : false;
  649. }
  650. inline bool Var::isStruct() const
  651. {
  652. VarHolder* pHolder = content();
  653. return pHolder ? pHolder->isStruct() : false;
  654. }
  655. inline bool Var::isInteger() const
  656. {
  657. VarHolder* pHolder = content();
  658. return pHolder ? pHolder->isInteger() : false;
  659. }
  660. inline bool Var::isSigned() const
  661. {
  662. VarHolder* pHolder = content();
  663. return pHolder ? pHolder->isSigned() : false;
  664. }
  665. inline bool Var::isNumeric() const
  666. {
  667. VarHolder* pHolder = content();
  668. return pHolder ? pHolder->isNumeric() : false;
  669. }
  670. inline bool Var::isBoolean() const
  671. {
  672. VarHolder* pHolder = content();
  673. return pHolder ? pHolder->isBoolean() : false;
  674. }
  675. inline bool Var::isString() const
  676. {
  677. VarHolder* pHolder = content();
  678. return pHolder ? pHolder->isString() : false;
  679. }
  680. inline bool Var::isDate() const
  681. {
  682. VarHolder* pHolder = content();
  683. return pHolder ? pHolder->isDate() : false;
  684. }
  685. inline bool Var::isTime() const
  686. {
  687. VarHolder* pHolder = content();
  688. return pHolder ? pHolder->isTime() : false;
  689. }
  690. inline bool Var::isDateTime() const
  691. {
  692. VarHolder* pHolder = content();
  693. return pHolder ? pHolder->isDateTime() : false;
  694. }
  695. inline std::size_t Var::size() const
  696. {
  697. VarHolder* pHolder = content();
  698. return pHolder ? pHolder->size() : 0;
  699. }
  700. ///
  701. /// Var non-member functions
  702. ///
  703. inline const Var operator + (const char* other, const Var& da)
  704. /// Addition operator for adding Var to const char*
  705. {
  706. std::string tmp = other;
  707. return tmp + da.convert<std::string>();
  708. }
  709. inline char operator + (const char& other, const Var& da)
  710. /// Addition operator for adding Var to char
  711. {
  712. return other + da.convert<char>();
  713. }
  714. inline char operator - (const char& other, const Var& da)
  715. /// Subtraction operator for subtracting Var from char
  716. {
  717. return other - da.convert<char>();
  718. }
  719. inline char operator * (const char& other, const Var& da)
  720. /// Multiplication operator for multiplying Var with char
  721. {
  722. return other * da.convert<char>();
  723. }
  724. inline char operator / (const char& other, const Var& da)
  725. /// Division operator for dividing Var with char
  726. {
  727. return other / da.convert<char>();
  728. }
  729. inline char operator += (char& other, const Var& da)
  730. /// Addition assignment operator for adding Var to char
  731. {
  732. return other += da.convert<char>();
  733. }
  734. inline char operator -= (char& other, const Var& da)
  735. /// Subtraction assignment operator for subtracting Var from char
  736. {
  737. return other -= da.convert<char>();
  738. }
  739. inline char operator *= (char& other, const Var& da)
  740. /// Multiplication assignment operator for multiplying Var with char
  741. {
  742. return other *= da.convert<char>();
  743. }
  744. inline char operator /= (char& other, const Var& da)
  745. /// Division assignment operator for dividing Var with char
  746. {
  747. return other /= da.convert<char>();
  748. }
  749. inline bool operator == (const char& other, const Var& da)
  750. /// Equality operator for comparing Var with char
  751. {
  752. if (da.isEmpty()) return false;
  753. return other == da.convert<char>();
  754. }
  755. inline bool operator != (const char& other, const Var& da)
  756. /// Inequality operator for comparing Var with char
  757. {
  758. if (da.isEmpty()) return true;
  759. return other != da.convert<char>();
  760. }
  761. inline bool operator < (const char& other, const Var& da)
  762. /// Less than operator for comparing Var with char
  763. {
  764. if (da.isEmpty()) return false;
  765. return other < da.convert<char>();
  766. }
  767. inline bool operator <= (const char& other, const Var& da)
  768. /// Less than or equal operator for comparing Var with char
  769. {
  770. if (da.isEmpty()) return false;
  771. return other <= da.convert<char>();
  772. }
  773. inline bool operator > (const char& other, const Var& da)
  774. /// Greater than operator for comparing Var with char
  775. {
  776. if (da.isEmpty())return false;
  777. return other > da.convert<char>();
  778. }
  779. inline bool operator >= (const char& other, const Var& da)
  780. /// Greater than or equal operator for comparing Var with char
  781. {
  782. if (da.isEmpty())return false;
  783. return other >= da.convert<char>();
  784. }
  785. inline Poco::Int8 operator + (const Poco::Int8& other, const Var& da)
  786. /// Addition operator for adding Var to Poco::Int8
  787. {
  788. return other + da.convert<Poco::Int8>();
  789. }
  790. inline Poco::Int8 operator - (const Poco::Int8& other, const Var& da)
  791. /// Subtraction operator for subtracting Var from Poco::Int8
  792. {
  793. return other - da.convert<Poco::Int8>();
  794. }
  795. inline Poco::Int8 operator * (const Poco::Int8& other, const Var& da)
  796. /// Multiplication operator for multiplying Var with Poco::Int8
  797. {
  798. return other * da.convert<Poco::Int8>();
  799. }
  800. inline Poco::Int8 operator / (const Poco::Int8& other, const Var& da)
  801. /// Division operator for dividing Var with Poco::Int8
  802. {
  803. return other / da.convert<Poco::Int8>();
  804. }
  805. inline Poco::Int8 operator += (Poco::Int8& other, const Var& da)
  806. /// Addition assignment operator for adding Var to Poco::Int8
  807. {
  808. return other += da.convert<Poco::Int8>();
  809. }
  810. inline Poco::Int8 operator -= (Poco::Int8& other, const Var& da)
  811. /// Subtraction assignment operator for subtracting Var from Poco::Int8
  812. {
  813. return other -= da.convert<Poco::Int8>();
  814. }
  815. inline Poco::Int8 operator *= (Poco::Int8& other, const Var& da)
  816. /// Multiplication assignment operator for multiplying Var with Poco::Int8
  817. {
  818. return other *= da.convert<Poco::Int8>();
  819. }
  820. inline Poco::Int8 operator /= (Poco::Int8& other, const Var& da)
  821. /// Division assignment operator for dividing Var with Poco::Int8
  822. {
  823. return other /= da.convert<Poco::Int8>();
  824. }
  825. inline bool operator == (const Poco::Int8& other, const Var& da)
  826. /// Equality operator for comparing Var with Poco::Int8
  827. {
  828. if (da.isEmpty()) return false;
  829. return other == da.convert<Poco::Int8>();
  830. }
  831. inline bool operator != (const Poco::Int8& other, const Var& da)
  832. /// Inequality operator for comparing Var with Poco::Int8
  833. {
  834. if (da.isEmpty()) return true;
  835. return other != da.convert<Poco::Int8>();
  836. }
  837. inline bool operator < (const Poco::Int8& other, const Var& da)
  838. /// Less than operator for comparing Var with Poco::Int8
  839. {
  840. if (da.isEmpty()) return false;
  841. return other < da.convert<Poco::Int8>();
  842. }
  843. inline bool operator <= (const Poco::Int8& other, const Var& da)
  844. /// Less than or equal operator for comparing Var with Poco::Int8
  845. {
  846. if (da.isEmpty()) return false;
  847. return other <= da.convert<Poco::Int8>();
  848. }
  849. inline bool operator > (const Poco::Int8& other, const Var& da)
  850. /// Greater than operator for comparing Var with Poco::Int8
  851. {
  852. if (da.isEmpty()) return false;
  853. return other > da.convert<Poco::Int8>();
  854. }
  855. inline bool operator >= (const Poco::Int8& other, const Var& da)
  856. /// Greater than or equal operator for comparing Var with Poco::Int8
  857. {
  858. if (da.isEmpty()) return false;
  859. return other >= da.convert<Poco::Int8>();
  860. }
  861. inline Poco::UInt8 operator + (const Poco::UInt8& other, const Var& da)
  862. /// Addition operator for adding Var to Poco::UInt8
  863. {
  864. return other + da.convert<Poco::UInt8>();
  865. }
  866. inline Poco::UInt8 operator - (const Poco::UInt8& other, const Var& da)
  867. /// Subtraction operator for subtracting Var from Poco::UInt8
  868. {
  869. return other - da.convert<Poco::UInt8>();
  870. }
  871. inline Poco::UInt8 operator * (const Poco::UInt8& other, const Var& da)
  872. /// Multiplication operator for multiplying Var with Poco::UInt8
  873. {
  874. return other * da.convert<Poco::UInt8>();
  875. }
  876. inline Poco::UInt8 operator / (const Poco::UInt8& other, const Var& da)
  877. /// Division operator for dividing Var with Poco::UInt8
  878. {
  879. return other / da.convert<Poco::UInt8>();
  880. }
  881. inline Poco::UInt8 operator += (Poco::UInt8& other, const Var& da)
  882. /// Addition assignment operator for adding Var to Poco::UInt8
  883. {
  884. return other += da.convert<Poco::UInt8>();
  885. }
  886. inline Poco::UInt8 operator -= (Poco::UInt8& other, const Var& da)
  887. /// Subtraction assignment operator for subtracting Var from Poco::UInt8
  888. {
  889. return other -= da.convert<Poco::UInt8>();
  890. }
  891. inline Poco::UInt8 operator *= (Poco::UInt8& other, const Var& da)
  892. /// Multiplication assignment operator for multiplying Var with Poco::UInt8
  893. {
  894. return other *= da.convert<Poco::UInt8>();
  895. }
  896. inline Poco::UInt8 operator /= (Poco::UInt8& other, const Var& da)
  897. /// Division assignment operator for dividing Var with Poco::UInt8
  898. {
  899. return other /= da.convert<Poco::UInt8>();
  900. }
  901. inline bool operator == (const Poco::UInt8& other, const Var& da)
  902. /// Equality operator for comparing Var with Poco::UInt8
  903. {
  904. if (da.isEmpty()) return false;
  905. return other == da.convert<Poco::UInt8>();
  906. }
  907. inline bool operator != (const Poco::UInt8& other, const Var& da)
  908. /// Inequality operator for comparing Var with Poco::UInt8
  909. {
  910. if (da.isEmpty()) return true;
  911. return other != da.convert<Poco::UInt8>();
  912. }
  913. inline bool operator < (const Poco::UInt8& other, const Var& da)
  914. /// Less than operator for comparing Var with Poco::UInt8
  915. {
  916. if (da.isEmpty()) return false;
  917. return other < da.convert<Poco::UInt8>();
  918. }
  919. inline bool operator <= (const Poco::UInt8& other, const Var& da)
  920. /// Less than or equal operator for comparing Var with Poco::UInt8
  921. {
  922. if (da.isEmpty()) return false;
  923. return other <= da.convert<Poco::UInt8>();
  924. }
  925. inline bool operator > (const Poco::UInt8& other, const Var& da)
  926. /// Greater than operator for comparing Var with Poco::UInt8
  927. {
  928. if (da.isEmpty()) return false;
  929. return other > da.convert<Poco::UInt8>();
  930. }
  931. inline bool operator >= (const Poco::UInt8& other, const Var& da)
  932. /// Greater than or equal operator for comparing Var with Poco::UInt8
  933. {
  934. if (da.isEmpty()) return false;
  935. return other >= da.convert<Poco::UInt8>();
  936. }
  937. inline Poco::Int16 operator + (const Poco::Int16& other, const Var& da)
  938. /// Addition operator for adding Var to Poco::Int16
  939. {
  940. return other + da.convert<Poco::Int16>();
  941. }
  942. inline Poco::Int16 operator - (const Poco::Int16& other, const Var& da)
  943. /// Subtraction operator for subtracting Var from Poco::Int16
  944. {
  945. return other - da.convert<Poco::Int16>();
  946. }
  947. inline Poco::Int16 operator * (const Poco::Int16& other, const Var& da)
  948. /// Multiplication operator for multiplying Var with Poco::Int16
  949. {
  950. return other * da.convert<Poco::Int16>();
  951. }
  952. inline Poco::Int16 operator / (const Poco::Int16& other, const Var& da)
  953. /// Division operator for dividing Var with Poco::Int16
  954. {
  955. return other / da.convert<Poco::Int16>();
  956. }
  957. inline Poco::Int16 operator += (Poco::Int16& other, const Var& da)
  958. /// Addition assignment operator for adding Var to Poco::Int16
  959. {
  960. return other += da.convert<Poco::Int16>();
  961. }
  962. inline Poco::Int16 operator -= (Poco::Int16& other, const Var& da)
  963. /// Subtraction assignment operator for subtracting Var from Poco::Int16
  964. {
  965. return other -= da.convert<Poco::Int16>();
  966. }
  967. inline Poco::Int16 operator *= (Poco::Int16& other, const Var& da)
  968. /// Multiplication assignment operator for multiplying Var with Poco::Int16
  969. {
  970. return other *= da.convert<Poco::Int16>();
  971. }
  972. inline Poco::Int16 operator /= (Poco::Int16& other, const Var& da)
  973. /// Division assignment operator for dividing Var with Poco::Int16
  974. {
  975. return other /= da.convert<Poco::Int16>();
  976. }
  977. inline bool operator == (const Poco::Int16& other, const Var& da)
  978. /// Equality operator for comparing Var with Poco::Int16
  979. {
  980. if (da.isEmpty()) return false;
  981. return other == da.convert<Poco::Int16>();
  982. }
  983. inline bool operator != (const Poco::Int16& other, const Var& da)
  984. /// Inequality operator for comparing Var with Poco::Int16
  985. {
  986. if (da.isEmpty()) return true;
  987. return other != da.convert<Poco::Int16>();
  988. }
  989. inline bool operator < (const Poco::Int16& other, const Var& da)
  990. /// Less than operator for comparing Var with Poco::Int16
  991. {
  992. if (da.isEmpty()) return false;
  993. return other < da.convert<Poco::Int16>();
  994. }
  995. inline bool operator <= (const Poco::Int16& other, const Var& da)
  996. /// Less than or equal operator for comparing Var with Poco::Int16
  997. {
  998. if (da.isEmpty()) return false;
  999. return other <= da.convert<Poco::Int16>();
  1000. }
  1001. inline bool operator > (const Poco::Int16& other, const Var& da)
  1002. /// Greater than operator for comparing Var with Poco::Int16
  1003. {
  1004. if (da.isEmpty()) return false;
  1005. return other > da.convert<Poco::Int16>();
  1006. }
  1007. inline bool operator >= (const Poco::Int16& other, const Var& da)
  1008. /// Greater than or equal operator for comparing Var with Poco::Int16
  1009. {
  1010. if (da.isEmpty()) return false;
  1011. return other >= da.convert<Poco::Int16>();
  1012. }
  1013. inline Poco::UInt16 operator + (const Poco::UInt16& other, const Var& da)
  1014. /// Addition operator for adding Var to Poco::UInt16
  1015. {
  1016. return other + da.convert<Poco::UInt16>();
  1017. }
  1018. inline Poco::UInt16 operator - (const Poco::UInt16& other, const Var& da)
  1019. /// Subtraction operator for subtracting Var from Poco::UInt16
  1020. {
  1021. return other - da.convert<Poco::UInt16>();
  1022. }
  1023. inline Poco::UInt16 operator * (const Poco::UInt16& other, const Var& da)
  1024. /// Multiplication operator for multiplying Var with Poco::UInt16
  1025. {
  1026. return other * da.convert<Poco::UInt16>();
  1027. }
  1028. inline Poco::UInt16 operator / (const Poco::UInt16& other, const Var& da)
  1029. /// Division operator for dividing Var with Poco::UInt16
  1030. {
  1031. return other / da.convert<Poco::UInt16>();
  1032. }
  1033. inline Poco::UInt16 operator += (Poco::UInt16& other, const Var& da)
  1034. /// Addition assignment operator for adding Var to Poco::UInt16
  1035. {
  1036. return other += da.convert<Poco::UInt16>();
  1037. }
  1038. inline Poco::UInt16 operator -= (Poco::UInt16& other, const Var& da)
  1039. /// Subtraction assignment operator for subtracting Var from Poco::UInt16
  1040. {
  1041. return other -= da.convert<Poco::UInt16>();
  1042. }
  1043. inline Poco::UInt16 operator *= (Poco::UInt16& other, const Var& da)
  1044. /// Multiplication assignment operator for multiplying Var with Poco::UInt16
  1045. {
  1046. return other *= da.convert<Poco::UInt16>();
  1047. }
  1048. inline Poco::UInt16 operator /= (Poco::UInt16& other, const Var& da)
  1049. /// Division assignment operator for dividing Var with Poco::UInt16
  1050. {
  1051. return other /= da.convert<Poco::UInt16>();
  1052. }
  1053. inline bool operator == (const Poco::UInt16& other, const Var& da)
  1054. /// Equality operator for comparing Var with Poco::UInt16
  1055. {
  1056. if (da.isEmpty()) return false;
  1057. return other == da.convert<Poco::UInt16>();
  1058. }
  1059. inline bool operator != (const Poco::UInt16& other, const Var& da)
  1060. /// Inequality operator for comparing Var with Poco::UInt16
  1061. {
  1062. if (da.isEmpty()) return true;
  1063. return other != da.convert<Poco::UInt16>();
  1064. }
  1065. inline bool operator < (const Poco::UInt16& other, const Var& da)
  1066. /// Less than operator for comparing Var with Poco::UInt16
  1067. {
  1068. if (da.isEmpty()) return false;
  1069. return other < da.convert<Poco::UInt16>();
  1070. }
  1071. inline bool operator <= (const Poco::UInt16& other, const Var& da)
  1072. /// Less than or equal operator for comparing Var with Poco::UInt16
  1073. {
  1074. if (da.isEmpty()) return false;
  1075. return other <= da.convert<Poco::UInt16>();
  1076. }
  1077. inline bool operator > (const Poco::UInt16& other, const Var& da)
  1078. /// Greater than operator for comparing Var with Poco::UInt16
  1079. {
  1080. if (da.isEmpty()) return false;
  1081. return other > da.convert<Poco::UInt16>();
  1082. }
  1083. inline bool operator >= (const Poco::UInt16& other, const Var& da)
  1084. /// Greater than or equal operator for comparing Var with Poco::UInt16
  1085. {
  1086. if (da.isEmpty()) return false;
  1087. return other >= da.convert<Poco::UInt16>();
  1088. }
  1089. inline Poco::Int32 operator + (const Poco::Int32& other, const Var& da)
  1090. /// Addition operator for adding Var to Poco::Int32
  1091. {
  1092. return other + da.convert<Poco::Int32>();
  1093. }
  1094. inline Poco::Int32 operator - (const Poco::Int32& other, const Var& da)
  1095. /// Subtraction operator for subtracting Var from Poco::Int32
  1096. {
  1097. return other - da.convert<Poco::Int32>();
  1098. }
  1099. inline Poco::Int32 operator * (const Poco::Int32& other, const Var& da)
  1100. /// Multiplication operator for multiplying Var with Poco::Int32
  1101. {
  1102. return other * da.convert<Poco::Int32>();
  1103. }
  1104. inline Poco::Int32 operator / (const Poco::Int32& other, const Var& da)
  1105. /// Division operator for dividing Var with Poco::Int32
  1106. {
  1107. return other / da.convert<Poco::Int32>();
  1108. }
  1109. inline Poco::Int32 operator += (Poco::Int32& other, const Var& da)
  1110. /// Addition assignment operator for adding Var to Poco::Int32
  1111. {
  1112. return other += da.convert<Poco::Int32>();
  1113. }
  1114. inline Poco::Int32 operator -= (Poco::Int32& other, const Var& da)
  1115. /// Subtraction assignment operator for subtracting Var from Poco::Int32
  1116. {
  1117. return other -= da.convert<Poco::Int32>();
  1118. }
  1119. inline Poco::Int32 operator *= (Poco::Int32& other, const Var& da)
  1120. /// Multiplication assignment operator for multiplying Var with Poco::Int32
  1121. {
  1122. return other *= da.convert<Poco::Int32>();
  1123. }
  1124. inline Poco::Int32 operator /= (Poco::Int32& other, const Var& da)
  1125. /// Division assignment operator for dividing Var with Poco::Int32
  1126. {
  1127. return other /= da.convert<Poco::Int32>();
  1128. }
  1129. inline bool operator == (const Poco::Int32& other, const Var& da)
  1130. /// Equality operator for comparing Var with Poco::Int32
  1131. {
  1132. if (da.isEmpty()) return false;
  1133. return other == da.convert<Poco::Int32>();
  1134. }
  1135. inline bool operator != (const Poco::Int32& other, const Var& da)
  1136. /// Inequality operator for comparing Var with Poco::Int32
  1137. {
  1138. if (da.isEmpty()) return true;
  1139. return other != da.convert<Poco::Int32>();
  1140. }
  1141. inline bool operator < (const Poco::Int32& other, const Var& da)
  1142. /// Less than operator for comparing Var with Poco::Int32
  1143. {
  1144. if (da.isEmpty()) return false;
  1145. return other < da.convert<Poco::Int32>();
  1146. }
  1147. inline bool operator <= (const Poco::Int32& other, const Var& da)
  1148. /// Less than or equal operator for comparing Var with Poco::Int32
  1149. {
  1150. if (da.isEmpty()) return false;
  1151. return other <= da.convert<Poco::Int32>();
  1152. }
  1153. inline bool operator > (const Poco::Int32& other, const Var& da)
  1154. /// Greater than operator for comparing Var with Poco::Int32
  1155. {
  1156. if (da.isEmpty()) return false;
  1157. return other > da.convert<Poco::Int32>();
  1158. }
  1159. inline bool operator >= (const Poco::Int32& other, const Var& da)
  1160. /// Greater than or equal operator for comparing Var with Poco::Int32
  1161. {
  1162. if (da.isEmpty()) return false;
  1163. return other >= da.convert<Poco::Int32>();
  1164. }
  1165. inline Poco::UInt32 operator + (const Poco::UInt32& other, const Var& da)
  1166. /// Addition operator for adding Var to Poco::UInt32
  1167. {
  1168. return other + da.convert<Poco::UInt32>();
  1169. }
  1170. inline Poco::UInt32 operator - (const Poco::UInt32& other, const Var& da)
  1171. /// Subtraction operator for subtracting Var from Poco::UInt32
  1172. {
  1173. return other - da.convert<Poco::UInt32>();
  1174. }
  1175. inline Poco::UInt32 operator * (const Poco::UInt32& other, const Var& da)
  1176. /// Multiplication operator for multiplying Var with Poco::UInt32
  1177. {
  1178. return other * da.convert<Poco::UInt32>();
  1179. }
  1180. inline Poco::UInt32 operator / (const Poco::UInt32& other, const Var& da)
  1181. /// Division operator for dividing Var with Poco::UInt32
  1182. {
  1183. return other / da.convert<Poco::UInt32>();
  1184. }
  1185. inline Poco::UInt32 operator += (Poco::UInt32& other, const Var& da)
  1186. /// Addition assignment operator for adding Var to Poco::UInt32
  1187. {
  1188. return other += da.convert<Poco::UInt32>();
  1189. }
  1190. inline Poco::UInt32 operator -= (Poco::UInt32& other, const Var& da)
  1191. /// Subtraction assignment operator for subtracting Var from Poco::UInt32
  1192. {
  1193. return other -= da.convert<Poco::UInt32>();
  1194. }
  1195. inline Poco::UInt32 operator *= (Poco::UInt32& other, const Var& da)
  1196. /// Multiplication assignment operator for multiplying Var with Poco::UInt32
  1197. {
  1198. return other *= da.convert<Poco::UInt32>();
  1199. }
  1200. inline Poco::UInt32 operator /= (Poco::UInt32& other, const Var& da)
  1201. /// Division assignment operator for dividing Var with Poco::UInt32
  1202. {
  1203. return other /= da.convert<Poco::UInt32>();
  1204. }
  1205. inline bool operator == (const Poco::UInt32& other, const Var& da)
  1206. /// Equality operator for comparing Var with Poco::UInt32
  1207. {
  1208. if (da.isEmpty()) return false;
  1209. return other == da.convert<Poco::UInt32>();
  1210. }
  1211. inline bool operator != (const Poco::UInt32& other, const Var& da)
  1212. /// Inequality operator for comparing Var with Poco::UInt32
  1213. {
  1214. if (da.isEmpty()) return true;
  1215. return other != da.convert<Poco::UInt32>();
  1216. }
  1217. inline bool operator < (const Poco::UInt32& other, const Var& da)
  1218. /// Less than operator for comparing Var with Poco::UInt32
  1219. {
  1220. if (da.isEmpty()) return false;
  1221. return other < da.convert<Poco::UInt32>();
  1222. }
  1223. inline bool operator <= (const Poco::UInt32& other, const Var& da)
  1224. /// Less than or equal operator for comparing Var with Poco::UInt32
  1225. {
  1226. if (da.isEmpty()) return false;
  1227. return other <= da.convert<Poco::UInt32>();
  1228. }
  1229. inline bool operator > (const Poco::UInt32& other, const Var& da)
  1230. /// Greater than operator for comparing Var with Poco::UInt32
  1231. {
  1232. if (da.isEmpty()) return false;
  1233. return other > da.convert<Poco::UInt32>();
  1234. }
  1235. inline bool operator >= (const Poco::UInt32& other, const Var& da)
  1236. /// Greater than or equal operator for comparing Var with Poco::UInt32
  1237. {
  1238. if (da.isEmpty()) return false;
  1239. return other >= da.convert<Poco::UInt32>();
  1240. }
  1241. inline Poco::Int64 operator + (const Poco::Int64& other, const Var& da)
  1242. /// Addition operator for adding Var to Poco::Int64
  1243. {
  1244. return other + da.convert<Poco::Int64>();
  1245. }
  1246. inline Poco::Int64 operator - (const Poco::Int64& other, const Var& da)
  1247. /// Subtraction operator for subtracting Var from Poco::Int64
  1248. {
  1249. return other - da.convert<Poco::Int64>();
  1250. }
  1251. inline Poco::Int64 operator * (const Poco::Int64& other, const Var& da)
  1252. /// Multiplication operator for multiplying Var with Poco::Int64
  1253. {
  1254. return other * da.convert<Poco::Int64>();
  1255. }
  1256. inline Poco::Int64 operator / (const Poco::Int64& other, const Var& da)
  1257. /// Division operator for dividing Var with Poco::Int64
  1258. {
  1259. return other / da.convert<Poco::Int64>();
  1260. }
  1261. inline Poco::Int64 operator += (Poco::Int64& other, const Var& da)
  1262. /// Addition assignment operator for adding Var to Poco::Int64
  1263. {
  1264. return other += da.convert<Poco::Int64>();
  1265. }
  1266. inline Poco::Int64 operator -= (Poco::Int64& other, const Var& da)
  1267. /// Subtraction assignment operator for subtracting Var from Poco::Int64
  1268. {
  1269. return other -= da.convert<Poco::Int64>();
  1270. }
  1271. inline Poco::Int64 operator *= (Poco::Int64& other, const Var& da)
  1272. /// Multiplication assignment operator for multiplying Var with Poco::Int64
  1273. {
  1274. return other *= da.convert<Poco::Int64>();
  1275. }
  1276. inline Poco::Int64 operator /= (Poco::Int64& other, const Var& da)
  1277. /// Division assignment operator for dividing Var with Poco::Int64
  1278. {
  1279. return other /= da.convert<Poco::Int64>();
  1280. }
  1281. inline bool operator == (const Poco::Int64& other, const Var& da)
  1282. /// Equality operator for comparing Var with Poco::Int64
  1283. {
  1284. if (da.isEmpty()) return false;
  1285. return other == da.convert<Poco::Int64>();
  1286. }
  1287. inline bool operator != (const Poco::Int64& other, const Var& da)
  1288. /// Inequality operator for comparing Var with Poco::Int64
  1289. {
  1290. if (da.isEmpty()) return true;
  1291. return other != da.convert<Poco::Int64>();
  1292. }
  1293. inline bool operator < (const Poco::Int64& other, const Var& da)
  1294. /// Less than operator for comparing Var with Poco::Int64
  1295. {
  1296. if (da.isEmpty()) return false;
  1297. return other < da.convert<Poco::Int64>();
  1298. }
  1299. inline bool operator <= (const Poco::Int64& other, const Var& da)
  1300. /// Less than or equal operator for comparing Var with Poco::Int64
  1301. {
  1302. if (da.isEmpty()) return false;
  1303. return other <= da.convert<Poco::Int64>();
  1304. }
  1305. inline bool operator > (const Poco::Int64& other, const Var& da)
  1306. /// Greater than operator for comparing Var with Poco::Int64
  1307. {
  1308. if (da.isEmpty()) return false;
  1309. return other > da.convert<Poco::Int64>();
  1310. }
  1311. inline bool operator >= (const Poco::Int64& other, const Var& da)
  1312. /// Greater than or equal operator for comparing Var with Poco::Int64
  1313. {
  1314. if (da.isEmpty()) return false;
  1315. return other >= da.convert<Poco::Int64>();
  1316. }
  1317. inline Poco::UInt64 operator + (const Poco::UInt64& other, const Var& da)
  1318. /// Addition operator for adding Var to Poco::UInt64
  1319. {
  1320. return other + da.convert<Poco::UInt64>();
  1321. }
  1322. inline Poco::UInt64 operator - (const Poco::UInt64& other, const Var& da)
  1323. /// Subtraction operator for subtracting Var from Poco::UInt64
  1324. {
  1325. return other - da.convert<Poco::UInt64>();
  1326. }
  1327. inline Poco::UInt64 operator * (const Poco::UInt64& other, const Var& da)
  1328. /// Multiplication operator for multiplying Var with Poco::UInt64
  1329. {
  1330. return other * da.convert<Poco::UInt64>();
  1331. }
  1332. inline Poco::UInt64 operator / (const Poco::UInt64& other, const Var& da)
  1333. /// Division operator for dividing Var with Poco::UInt64
  1334. {
  1335. return other / da.convert<Poco::UInt64>();
  1336. }
  1337. inline Poco::UInt64 operator += (Poco::UInt64& other, const Var& da)
  1338. /// Addition assignment operator for adding Var to Poco::UInt64
  1339. {
  1340. return other += da.convert<Poco::UInt64>();
  1341. }
  1342. inline Poco::UInt64 operator -= (Poco::UInt64& other, const Var& da)
  1343. /// Subtraction assignment operator for subtracting Var from Poco::UInt64
  1344. {
  1345. return other -= da.convert<Poco::UInt64>();
  1346. }
  1347. inline Poco::UInt64 operator *= (Poco::UInt64& other, const Var& da)
  1348. /// Multiplication assignment operator for multiplying Var with Poco::UInt64
  1349. {
  1350. return other *= da.convert<Poco::UInt64>();
  1351. }
  1352. inline Poco::UInt64 operator /= (Poco::UInt64& other, const Var& da)
  1353. /// Division assignment operator for dividing Var with Poco::UInt64
  1354. {
  1355. return other /= da.convert<Poco::UInt64>();
  1356. }
  1357. inline bool operator == (const Poco::UInt64& other, const Var& da)
  1358. /// Equality operator for comparing Var with Poco::UInt64
  1359. {
  1360. if (da.isEmpty()) return false;
  1361. return other == da.convert<Poco::UInt64>();
  1362. }
  1363. inline bool operator != (const Poco::UInt64& other, const Var& da)
  1364. /// Inequality operator for comparing Var with Poco::UInt64
  1365. {
  1366. if (da.isEmpty()) return true;
  1367. return other != da.convert<Poco::UInt64>();
  1368. }
  1369. inline bool operator < (const Poco::UInt64& other, const Var& da)
  1370. /// Less than operator for comparing Var with Poco::UInt64
  1371. {
  1372. if (da.isEmpty()) return false;
  1373. return other < da.convert<Poco::UInt64>();
  1374. }
  1375. inline bool operator <= (const Poco::UInt64& other, const Var& da)
  1376. /// Less than or equal operator for comparing Var with Poco::UInt64
  1377. {
  1378. if (da.isEmpty()) return false;
  1379. return other <= da.convert<Poco::UInt64>();
  1380. }
  1381. inline bool operator > (const Poco::UInt64& other, const Var& da)
  1382. /// Greater than operator for comparing Var with Poco::UInt64
  1383. {
  1384. if (da.isEmpty()) return false;
  1385. return other > da.convert<Poco::UInt64>();
  1386. }
  1387. inline bool operator >= (const Poco::UInt64& other, const Var& da)
  1388. /// Greater than or equal operator for comparing Var with Poco::UInt64
  1389. {
  1390. if (da.isEmpty()) return false;
  1391. return other >= da.convert<Poco::UInt64>();
  1392. }
  1393. inline float operator + (const float& other, const Var& da)
  1394. /// Addition operator for adding Var to float
  1395. {
  1396. return other + da.convert<float>();
  1397. }
  1398. inline float operator - (const float& other, const Var& da)
  1399. /// Subtraction operator for subtracting Var from float
  1400. {
  1401. return other - da.convert<float>();
  1402. }
  1403. inline float operator * (const float& other, const Var& da)
  1404. /// Multiplication operator for multiplying Var with float
  1405. {
  1406. return other * da.convert<float>();
  1407. }
  1408. inline float operator / (const float& other, const Var& da)
  1409. /// Division operator for dividing Var with float
  1410. {
  1411. return other / da.convert<float>();
  1412. }
  1413. inline float operator += (float& other, const Var& da)
  1414. /// Addition assignment operator for adding Var to float
  1415. {
  1416. return other += da.convert<float>();
  1417. }
  1418. inline float operator -= (float& other, const Var& da)
  1419. /// Subtraction assignment operator for subtracting Var from float
  1420. {
  1421. return other -= da.convert<float>();
  1422. }
  1423. inline float operator *= (float& other, const Var& da)
  1424. /// Multiplication assignment operator for multiplying Var with float
  1425. {
  1426. return other *= da.convert<float>();
  1427. }
  1428. inline float operator /= (float& other, const Var& da)
  1429. /// Division assignment operator for dividing Var with float
  1430. {
  1431. return other /= da.convert<float>();
  1432. }
  1433. inline bool operator == (const float& other, const Var& da)
  1434. /// Equality operator for comparing Var with float
  1435. {
  1436. if (da.isEmpty()) return false;
  1437. return other == da.convert<float>();
  1438. }
  1439. inline bool operator != (const float& other, const Var& da)
  1440. /// Inequality operator for comparing Var with float
  1441. {
  1442. if (da.isEmpty()) return true;
  1443. return other != da.convert<float>();
  1444. }
  1445. inline bool operator < (const float& other, const Var& da)
  1446. /// Less than operator for comparing Var with float
  1447. {
  1448. if (da.isEmpty()) return false;
  1449. return other < da.convert<float>();
  1450. }
  1451. inline bool operator <= (const float& other, const Var& da)
  1452. /// Less than or equal operator for comparing Var with float
  1453. {
  1454. if (da.isEmpty()) return false;
  1455. return other <= da.convert<float>();
  1456. }
  1457. inline bool operator > (const float& other, const Var& da)
  1458. /// Greater than operator for comparing Var with float
  1459. {
  1460. if (da.isEmpty()) return false;
  1461. return other > da.convert<float>();
  1462. }
  1463. inline bool operator >= (const float& other, const Var& da)
  1464. /// Greater than or equal operator for comparing Var with float
  1465. {
  1466. if (da.isEmpty()) return false;
  1467. return other >= da.convert<float>();
  1468. }
  1469. inline double operator + (const double& other, const Var& da)
  1470. /// Addition operator for adding Var to double
  1471. {
  1472. return other + da.convert<double>();
  1473. }
  1474. inline double operator - (const double& other, const Var& da)
  1475. /// Subtraction operator for subtracting Var from double
  1476. {
  1477. return other - da.convert<double>();
  1478. }
  1479. inline double operator * (const double& other, const Var& da)
  1480. /// Multiplication operator for multiplying Var with double
  1481. {
  1482. return other * da.convert<double>();
  1483. }
  1484. inline double operator / (const double& other, const Var& da)
  1485. /// Division operator for dividing Var with double
  1486. {
  1487. return other / da.convert<double>();
  1488. }
  1489. inline double operator += (double& other, const Var& da)
  1490. /// Addition assignment operator for adding Var to double
  1491. {
  1492. return other += da.convert<double>();
  1493. }
  1494. inline double operator -= (double& other, const Var& da)
  1495. /// Subtraction assignment operator for subtracting Var from double
  1496. {
  1497. return other -= da.convert<double>();
  1498. }
  1499. inline double operator *= (double& other, const Var& da)
  1500. /// Multiplication assignment operator for multiplying Var with double
  1501. {
  1502. return other *= da.convert<double>();
  1503. }
  1504. inline double operator /= (double& other, const Var& da)
  1505. /// Division assignment operator for dividing Var with double
  1506. {
  1507. return other /= da.convert<double>();
  1508. }
  1509. inline bool operator == (const double& other, const Var& da)
  1510. /// Equality operator for comparing Var with double
  1511. {
  1512. if (da.isEmpty()) return false;
  1513. return other == da.convert<double>();
  1514. }
  1515. inline bool operator != (const double& other, const Var& da)
  1516. /// Inequality operator for comparing Var with double
  1517. {
  1518. if (da.isEmpty()) return true;
  1519. return other != da.convert<double>();
  1520. }
  1521. inline bool operator < (const double& other, const Var& da)
  1522. /// Less than operator for comparing Var with double
  1523. {
  1524. if (da.isEmpty()) return false;
  1525. return other < da.convert<double>();
  1526. }
  1527. inline bool operator <= (const double& other, const Var& da)
  1528. /// Less than or equal operator for comparing Var with double
  1529. {
  1530. if (da.isEmpty()) return false;
  1531. return other <= da.convert<double>();
  1532. }
  1533. inline bool operator > (const double& other, const Var& da)
  1534. /// Greater than operator for comparing Var with double
  1535. {
  1536. if (da.isEmpty()) return false;
  1537. return other > da.convert<double>();
  1538. }
  1539. inline bool operator >= (const double& other, const Var& da)
  1540. /// Greater than or equal operator for comparing Var with double
  1541. {
  1542. if (da.isEmpty()) return false;
  1543. return other >= da.convert<double>();
  1544. }
  1545. inline bool operator == (const bool& other, const Var& da)
  1546. /// Equality operator for comparing Var with bool
  1547. {
  1548. if (da.isEmpty()) return false;
  1549. return other == da.convert<bool>();
  1550. }
  1551. inline bool operator != (const bool& other, const Var& da)
  1552. /// Inequality operator for comparing Var with bool
  1553. {
  1554. if (da.isEmpty()) return true;
  1555. return other != da.convert<bool>();
  1556. }
  1557. inline bool operator == (const std::string& other, const Var& da)
  1558. /// Equality operator for comparing Var with std::string
  1559. {
  1560. if (da.isEmpty()) return false;
  1561. return other == da.convert<std::string>();
  1562. }
  1563. inline bool operator != (const std::string& other, const Var& da)
  1564. /// Inequality operator for comparing Var with std::string
  1565. {
  1566. if (da.isEmpty()) return true;
  1567. return other != da.convert<std::string>();
  1568. }
  1569. inline bool operator == (const UTF16String& other, const Var& da)
  1570. /// Equality operator for comparing Var with UTF16String
  1571. {
  1572. if (da.isEmpty()) return false;
  1573. return other == da.convert<UTF16String>();
  1574. }
  1575. inline bool operator != (const UTF16String& other, const Var& da)
  1576. /// Inequality operator for comparing Var with UTF16String
  1577. {
  1578. if (da.isEmpty()) return true;
  1579. return other != da.convert<UTF16String>();
  1580. }
  1581. inline bool operator == (const char* other, const Var& da)
  1582. /// Equality operator for comparing Var with const char*
  1583. {
  1584. if (da.isEmpty()) return false;
  1585. return da.convert<std::string>() == other;
  1586. }
  1587. inline bool operator != (const char* other, const Var& da)
  1588. /// Inequality operator for comparing Var with const char*
  1589. {
  1590. if (da.isEmpty()) return true;
  1591. return da.convert<std::string>() != other;
  1592. }
  1593. #ifndef POCO_LONG_IS_64_BIT
  1594. inline long operator + (const long& other, const Var& da)
  1595. /// Addition operator for adding Var to long
  1596. {
  1597. return other + da.convert<long>();
  1598. }
  1599. inline long operator - (const long& other, const Var& da)
  1600. /// Subtraction operator for subtracting Var from long
  1601. {
  1602. return other - da.convert<long>();
  1603. }
  1604. inline long operator * (const long& other, const Var& da)
  1605. /// Multiplication operator for multiplying Var with long
  1606. {
  1607. return other * da.convert<long>();
  1608. }
  1609. inline long operator / (const long& other, const Var& da)
  1610. /// Division operator for dividing Var with long
  1611. {
  1612. return other / da.convert<long>();
  1613. }
  1614. inline long operator += (long& other, const Var& da)
  1615. /// Addition assignment operator for adding Var to long
  1616. {
  1617. return other += da.convert<long>();
  1618. }
  1619. inline long operator -= (long& other, const Var& da)
  1620. /// Subtraction assignment operator for subtracting Var from long
  1621. {
  1622. return other -= da.convert<long>();
  1623. }
  1624. inline long operator *= (long& other, const Var& da)
  1625. /// Multiplication assignment operator for multiplying Var with long
  1626. {
  1627. return other *= da.convert<long>();
  1628. }
  1629. inline long operator /= (long& other, const Var& da)
  1630. /// Division assignment operator for dividing Var with long
  1631. {
  1632. return other /= da.convert<long>();
  1633. }
  1634. inline bool operator == (const long& other, const Var& da)
  1635. /// Equality operator for comparing Var with long
  1636. {
  1637. if (da.isEmpty()) return false;
  1638. return other == da.convert<long>();
  1639. }
  1640. inline bool operator != (const long& other, const Var& da)
  1641. /// Inequality operator for comparing Var with long
  1642. {
  1643. if (da.isEmpty()) return true;
  1644. return other != da.convert<long>();
  1645. }
  1646. inline bool operator < (const long& other, const Var& da)
  1647. /// Less than operator for comparing Var with long
  1648. {
  1649. if (da.isEmpty()) return false;
  1650. return other < da.convert<long>();
  1651. }
  1652. inline bool operator <= (const long& other, const Var& da)
  1653. /// Less than or equal operator for comparing Var with long
  1654. {
  1655. if (da.isEmpty()) return false;
  1656. return other <= da.convert<long>();
  1657. }
  1658. inline bool operator > (const long& other, const Var& da)
  1659. /// Greater than operator for comparing Var with long
  1660. {
  1661. if (da.isEmpty()) return false;
  1662. return other > da.convert<long>();
  1663. }
  1664. inline bool operator >= (const long& other, const Var& da)
  1665. /// Greater than or equal operator for comparing Var with long
  1666. {
  1667. if (da.isEmpty()) return false;
  1668. return other >= da.convert<long>();
  1669. }
  1670. #endif // POCO_LONG_IS_64_BIT
  1671. } // namespace Dynamic
  1672. //@ deprecated
  1673. typedef Dynamic::Var DynamicAny;
  1674. } // namespace Poco
  1675. #endif // Foundation_Var_INCLUDED