1 //
2 // Struct.h
3 //
4 // Library: Foundation
5 // Package: Dynamic
6 // Module:  Struct
7 //
8 // Definition of the Struct class.
9 //
10 // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier:	BSL-1.0
14 //
15 
16 
17 #ifndef Foundation_Struct_INCLUDED
18 #define Foundation_Struct_INCLUDED
19 
20 
21 #include "Poco/Foundation.h"
22 #include "Poco/Dynamic/Var.h"
23 #include "Poco/Dynamic/VarHolder.h"
24 #include "Poco/SharedPtr.h"
25 #include "Poco/OrderedMap.h"
26 #include "Poco/OrderedSet.h"
27 #include <map>
28 #include <set>
29 
30 
31 namespace Poco {
32 namespace Dynamic {
33 
34 
35 template <typename K, typename M = std::map<K, Var>, typename S = std::set<K>>
36 class Struct
37 	/// Struct allows to define a named collection of Var objects.
38 {
39 public:
40 	typedef M Data;
41 	typedef S NameSet;
42 	typedef typename Data::iterator Iterator;
43 	typedef typename Data::const_iterator ConstIterator;
44 	typedef typename Struct<K>::Data::value_type ValueType;
45 	typedef typename Struct<K>::Data::size_type SizeType;
46 	typedef typename std::pair<typename Struct<K, M, S>::Iterator, bool> InsRetVal;
47 	typedef typename Poco::SharedPtr<Struct<K, M, S>> Ptr;
48 
Struct()49 	Struct(): _data()
50 		/// Creates an empty Struct
51 	{
52 	}
53 
Struct(const Data & val)54 	Struct(const Data& val): _data(val)
55 		/// Creates the Struct from the given value.
56 	{
57 	}
58 
59 	template <typename T>
Struct(const std::map<K,T> & val)60 	Struct(const std::map<K, T>& val)
61 	{
62 		assignMap(val);
63 	}
64 
65 	template <typename T>
Struct(const OrderedMap<K,T> & val)66 	Struct(const OrderedMap<K, T>& val)
67 	{
68 		assignMap(val);
69 	}
70 
~Struct()71 	virtual ~Struct()
72 		/// Destroys the Struct.
73 	{
74 	}
75 
76 	inline Var& operator [] (const K& name)
77 		/// Returns the Var with the given name, creates an entry if not found.
78 	{
79 		return _data[name];
80 	}
81 
82 	const Var& operator [] (const K& name) const
83 		/// Returns the Var with the given name, throws a
84 		/// NotFoundException if the data member is not found.
85 	{
86 		ConstIterator it = find(name);
87 		if (it == end()) throw NotFoundException(name);
88 		return it->second;
89 	}
90 
contains(const K & name)91 	inline bool contains(const K& name) const
92 		/// Returns true if the Struct contains a member with the given name
93 	{
94 		return find(name) != end();
95 	}
96 
find(const K & name)97 	inline Iterator find(const K& name)
98 		/// Returns an iterator, pointing to the <name,Var> pair containing
99 		/// the element, or it returns end() if the member was not found
100 	{
101 		return _data.find(name);
102 	}
103 
find(const K & name)104 	inline ConstIterator find(const K& name) const
105 		/// Returns a const iterator, pointing to the <name,Var> pair containing
106 		/// the element, or it returns end() if the member was not found
107 	{
108 		return _data.find(name);
109 	}
110 
end()111 	inline Iterator end()
112 		/// Returns the end iterator for the Struct
113 	{
114 		return _data.end();
115 	}
116 
end()117 	inline ConstIterator end() const
118 		/// Returns the end const iterator for the Struct
119 	{
120 		return _data.end();
121 	}
122 
begin()123 	inline Iterator begin()
124 		/// Returns the begin iterator for the Struct
125 	{
126 		return _data.begin();
127 	}
128 
begin()129 	inline ConstIterator begin() const
130 		/// Returns the begin const iterator for the Struct
131 	{
132 		return _data.begin();
133 	}
134 
135 	template <typename T>
insert(const K & key,const T & value)136 	inline InsRetVal insert(const K& key, const T& value)
137 		/// Inserts a <name, Var> pair into the Struct,
138 		/// returns a pair containing the iterator and a boolean which
139 		/// indicates success or not (is true, when insert succeeded, false,
140 		/// when already another element was present, in this case Iterator
141 		/// points to that other element)
142 	{
143 		// fix: SunPro C++ is silly ...
144 		ValueType valueType(key, value);
145 		return insert(valueType);
146 	}
147 
insert(const ValueType & aPair)148 	inline InsRetVal insert(const ValueType& aPair)
149 		/// Inserts a <name, Var> pair into the Struct,
150 		/// returns a pair containing the iterator and a boolean which
151 		/// indicates success or not (is true, when insert succeeded, false,
152 		/// when already another element was present, in this case Iterator
153 		/// points to that other element)
154 	{
155 		return _data.insert(aPair);
156 	}
157 
erase(const K & key)158 	inline SizeType erase(const K& key)
159 		/// Erases the element if found, returns number of elements deleted
160 	{
161 		return _data.erase(key);
162 	}
163 
erase(Iterator & it)164 	inline void erase(Iterator& it)
165 		/// Erases the element at the given position
166 	{
167 		_data.erase(it);
168 	}
169 
clear()170 	inline void clear()
171 		/// Remove all elements from the struct
172 	{
173 		_data.clear();
174 	}
175 
swap(Struct & other)176 	inline void swap(Struct& other)
177 		/// Swap content of Struct with another Struct
178 	{
179 		_data.swap(other._data);
180 	}
181 
empty()182 	inline bool empty() const
183 		/// Returns true if the Struct doesn't contain any members
184 	{
185 		return _data.empty();
186 	}
187 
size()188 	SizeType size() const
189 		/// Returns the number of members the Struct contains
190 	{
191 		return _data.size();
192 	}
193 
members()194 	inline NameSet members() const
195 		/// Returns a sorted collection containing all member names
196 	{
197 		NameSet keys;
198 		ConstIterator it = begin();
199 		ConstIterator itEnd = end();
200 		for (; it != itEnd; ++it) keys.insert(it->first);
201 		return keys;
202 	}
203 
getVar(const K & key)204 	inline Var getVar(const K& key) const
205 		/// Returns the var value of the element with the given name.
206 		/// Throws a NotFoundException if the key does not exist.
207 	{
208 		ConstIterator it = find(key);
209 		if(it == end())
210 		{
211 			throw NotFoundException("Key not found in Struct");
212 		}
213 		return it->second;
214 	}
215 
216 	template<typename DefT = Var>
getVar(const K & key,const DefT & defaultValue)217 	inline Var getVar(const K& key, const DefT& defaultValue) const
218 		/// Returns the var value of the element with the given name.
219 		/// or defaultValue if none is found.
220 	{
221 		ConstIterator it = find(key);
222 		if(it == end())
223 		{
224 			return defaultValue;
225 		}
226 		return it->second;
227 	}
228 
toString()229 	std::string toString() const
230 	{
231 		std::string str;
232 		Var(*this).template convert<std::string>(str);
233 		return str;
234 	}
235 
236 private:
237 	template <typename T>
assignMap(const T & map)238 	void assignMap(const T& map)
239 	{
240 		typedef typename T::const_iterator MapConstIterator;
241 
242 		MapConstIterator it = map.begin();
243 		MapConstIterator end = map.end();
244 		for (; it != end; ++it) _data.insert(ValueType(it->first, Var(it->second)));
245 	}
246 
247 	Data _data;
248 };
249 
250 
251 template <>
252 class VarHolderImpl<Struct<std::string, std::map<std::string, Var>, std::set<std::string>>>: public VarHolder
253 {
254 public:
255 	typedef std::string KeyType;
256 	typedef std::map<KeyType, Var> MapType;
257 	typedef std::set<KeyType> SetType;
258 	typedef Struct<KeyType, MapType, SetType> ValueType;
259 
VarHolderImpl(const ValueType & val)260 	VarHolderImpl(const ValueType& val): _val(val)
261 	{
262 	}
263 
~VarHolderImpl()264 	~VarHolderImpl()
265 	{
266 	}
267 
type()268 	const std::type_info& type() const
269 	{
270 		return typeid(ValueType);
271 	}
272 
convert(Int8 &)273 	void convert(Int8&) const
274 	{
275 		throw BadCastException("Cannot cast Struct type to Int8");
276 	}
277 
convert(Int16 &)278 	void convert(Int16&) const
279 	{
280 		throw BadCastException("Cannot cast Struct type to Int16");
281 	}
282 
convert(Int32 &)283 	void convert(Int32&) const
284 	{
285 		throw BadCastException("Cannot cast Struct type to Int32");
286 	}
287 
convert(Int64 &)288 	void convert(Int64&) const
289 	{
290 		throw BadCastException("Cannot cast Struct type to Int64");
291 	}
292 
convert(UInt8 &)293 	void convert(UInt8&) const
294 	{
295 		throw BadCastException("Cannot cast Struct type to UInt8");
296 	}
297 
convert(UInt16 &)298 	void convert(UInt16&) const
299 	{
300 		throw BadCastException("Cannot cast Struct type to UInt16");
301 	}
302 
convert(UInt32 &)303 	void convert(UInt32&) const
304 	{
305 		throw BadCastException("Cannot cast Struct type to UInt32");
306 	}
307 
convert(UInt64 &)308 	void convert(UInt64&) const
309 	{
310 		throw BadCastException("Cannot cast Struct type to UInt64");
311 	}
312 
convert(bool &)313 	void convert(bool&) const
314 	{
315 		throw BadCastException("Cannot cast Struct type to bool");
316 	}
317 
convert(float &)318 	void convert(float&) const
319 	{
320 		throw BadCastException("Cannot cast Struct type to float");
321 	}
322 
convert(double &)323 	void convert(double&) const
324 	{
325 		throw BadCastException("Cannot cast Struct type to double");
326 	}
327 
convert(char &)328 	void convert(char&) const
329 	{
330 		throw BadCastException("Cannot cast Struct type to char");
331 	}
332 
convert(std::string & val)333 	void convert(std::string& val) const
334 	{
335 		val.append("{ ");
336 		ValueType::ConstIterator it = _val.begin();
337 		ValueType::ConstIterator itEnd = _val.end();
338 		if (!_val.empty())
339 		{
340 			Var key(it->first);
341 			Impl::appendJSONKey(val, key);
342 			val.append(" : ");
343 			Impl::appendJSONValue(val, it->second);
344 			++it;
345 		}
346 		for (; it != itEnd; ++it)
347 		{
348 			val.append(", ");
349 			Var key(it->first);
350 			Impl::appendJSONKey(val, key);
351 			val.append(" : ");
352 			Impl::appendJSONValue(val, it->second);
353 		}
354 		val.append(" }");
355 	}
356 
convert(Poco::DateTime &)357 	void convert(Poco::DateTime&) const
358 	{
359 		throw BadCastException("Struct -> Poco::DateTime");
360 	}
361 
convert(Poco::LocalDateTime &)362 	void convert(Poco::LocalDateTime&) const
363 	{
364 		throw BadCastException("Struct -> Poco::LocalDateTime");
365 	}
366 
convert(Poco::Timestamp &)367 	void convert(Poco::Timestamp&) const
368 	{
369 		throw BadCastException("Struct -> Poco::Timestamp");
370 	}
371 
372 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
373 	{
374 		return cloneHolder(pVarHolder, _val);
375 	}
376 
value()377 	const ValueType& value() const
378 	{
379 		return _val;
380 	}
381 
isArray()382 	bool isArray() const
383 	{
384 		return false;
385 	}
386 
isStruct()387 	bool isStruct() const
388 	{
389 		return true;
390 	}
391 
isOrdered()392 	bool isOrdered() const
393 	{
394 		return false;
395 	}
396 
isInteger()397 	bool isInteger() const
398 	{
399 		return false;
400 	}
401 
isSigned()402 	bool isSigned() const
403 	{
404 		return false;
405 	}
406 
isNumeric()407 	bool isNumeric() const
408 	{
409 		return false;
410 	}
411 
isString()412 	bool isString() const
413 	{
414 		return false;
415 	}
416 
size()417 	std::size_t size() const
418 	{
419 		return _val.size();
420 	}
421 
422 	Var& operator [] (const KeyType& name)
423 	{
424 		return _val[name];
425 	}
426 
427 	const Var& operator [] (const KeyType& name) const
428 	{
429 		return _val[name];
430 	}
431 
432 private:
433 	ValueType _val;
434 };
435 
436 
437 template <>
438 class VarHolderImpl<Struct<int, std::map<int, Var>, std::set<int>>> : public VarHolder
439 {
440 public:
441 	typedef int KeyType;
442 	typedef std::map<KeyType, Var> MapType;
443 	typedef std::set<KeyType> SetType;
444 	typedef Struct<KeyType, MapType, SetType> ValueType;
445 
VarHolderImpl(const ValueType & val)446 	VarHolderImpl(const ValueType& val) : _val(val)
447 	{
448 	}
449 
~VarHolderImpl()450 	~VarHolderImpl()
451 	{
452 	}
453 
type()454 	const std::type_info& type() const
455 	{
456 		return typeid(ValueType);
457 	}
458 
convert(Int8 &)459 	void convert(Int8&) const
460 	{
461 		throw BadCastException("Cannot cast Struct type to Int8");
462 	}
463 
convert(Int16 &)464 	void convert(Int16&) const
465 	{
466 		throw BadCastException("Cannot cast Struct type to Int16");
467 	}
468 
convert(Int32 &)469 	void convert(Int32&) const
470 	{
471 		throw BadCastException("Cannot cast Struct type to Int32");
472 	}
473 
convert(Int64 &)474 	void convert(Int64&) const
475 	{
476 		throw BadCastException("Cannot cast Struct type to Int64");
477 	}
478 
convert(UInt8 &)479 	void convert(UInt8&) const
480 	{
481 		throw BadCastException("Cannot cast Struct type to UInt8");
482 	}
483 
convert(UInt16 &)484 	void convert(UInt16&) const
485 	{
486 		throw BadCastException("Cannot cast Struct type to UInt16");
487 	}
488 
convert(UInt32 &)489 	void convert(UInt32&) const
490 	{
491 		throw BadCastException("Cannot cast Struct type to UInt32");
492 	}
493 
convert(UInt64 &)494 	void convert(UInt64&) const
495 	{
496 		throw BadCastException("Cannot cast Struct type to UInt64");
497 	}
498 
convert(bool &)499 	void convert(bool&) const
500 	{
501 		throw BadCastException("Cannot cast Struct type to bool");
502 	}
503 
convert(float &)504 	void convert(float&) const
505 	{
506 		throw BadCastException("Cannot cast Struct type to float");
507 	}
508 
convert(double &)509 	void convert(double&) const
510 	{
511 		throw BadCastException("Cannot cast Struct type to double");
512 	}
513 
convert(char &)514 	void convert(char&) const
515 	{
516 		throw BadCastException("Cannot cast Struct type to char");
517 	}
518 
convert(std::string & val)519 	void convert(std::string& val) const
520 	{
521 		val.append("{ ");
522 		ValueType::ConstIterator it = _val.begin();
523 		ValueType::ConstIterator itEnd = _val.end();
524 		if (!_val.empty())
525 		{
526 			Var key(it->first);
527 			Impl::appendJSONKey(val, key);
528 			val.append(" : ");
529 			Impl::appendJSONValue(val, it->second);
530 			++it;
531 		}
532 		for (; it != itEnd; ++it)
533 		{
534 			val.append(", ");
535 			Var key(it->first);
536 			Impl::appendJSONKey(val, key);
537 			val.append(" : ");
538 			Impl::appendJSONValue(val, it->second);
539 		}
540 		val.append(" }");
541 	}
542 
convert(Poco::DateTime &)543 	void convert(Poco::DateTime&) const
544 	{
545 		throw BadCastException("Struct -> Poco::DateTime");
546 	}
547 
convert(Poco::LocalDateTime &)548 	void convert(Poco::LocalDateTime&) const
549 	{
550 		throw BadCastException("Struct -> Poco::LocalDateTime");
551 	}
552 
convert(Poco::Timestamp &)553 	void convert(Poco::Timestamp&) const
554 	{
555 		throw BadCastException("Struct -> Poco::Timestamp");
556 	}
557 
558 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
559 	{
560 		return cloneHolder(pVarHolder, _val);
561 	}
562 
value()563 	const ValueType& value() const
564 	{
565 		return _val;
566 	}
567 
isArray()568 	bool isArray() const
569 	{
570 		return false;
571 	}
572 
isStruct()573 	bool isStruct() const
574 	{
575 		return true;
576 	}
577 
isOrdered()578 	bool isOrdered() const
579 	{
580 		return false;
581 	}
582 
isInteger()583 	bool isInteger() const
584 	{
585 		return false;
586 	}
587 
isSigned()588 	bool isSigned() const
589 	{
590 		return false;
591 	}
592 
isNumeric()593 	bool isNumeric() const
594 	{
595 		return false;
596 	}
597 
isString()598 	bool isString() const
599 	{
600 		return false;
601 	}
602 
size()603 	std::size_t size() const
604 	{
605 		return _val.size();
606 	}
607 
608 	Var& operator [] (const KeyType& name)
609 	{
610 		return _val[name];
611 	}
612 
613 	const Var& operator [] (const KeyType& name) const
614 	{
615 		return _val[name];
616 	}
617 
618 private:
619 	ValueType _val;
620 };
621 
622 
623 template <>
624 class VarHolderImpl<Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>> : public VarHolder
625 {
626 public:
627 	typedef std::string KeyType;
628 	typedef Poco::OrderedMap<KeyType, Var> MapType;
629 	typedef Poco::OrderedSet<KeyType> SetType;
630 	typedef Struct<KeyType, MapType, SetType> ValueType;
631 
VarHolderImpl(const ValueType & val)632 	VarHolderImpl(const ValueType& val) : _val(val)
633 	{
634 	}
635 
~VarHolderImpl()636 	~VarHolderImpl()
637 	{
638 	}
639 
type()640 	const std::type_info& type() const
641 	{
642 		return typeid(ValueType);
643 	}
644 
convert(Int8 &)645 	void convert(Int8&) const
646 	{
647 		throw BadCastException("Cannot cast Struct type to Int8");
648 	}
649 
convert(Int16 &)650 	void convert(Int16&) const
651 	{
652 		throw BadCastException("Cannot cast Struct type to Int16");
653 	}
654 
convert(Int32 &)655 	void convert(Int32&) const
656 	{
657 		throw BadCastException("Cannot cast Struct type to Int32");
658 	}
659 
convert(Int64 &)660 	void convert(Int64&) const
661 	{
662 		throw BadCastException("Cannot cast Struct type to Int64");
663 	}
664 
convert(UInt8 &)665 	void convert(UInt8&) const
666 	{
667 		throw BadCastException("Cannot cast Struct type to UInt8");
668 	}
669 
convert(UInt16 &)670 	void convert(UInt16&) const
671 	{
672 		throw BadCastException("Cannot cast Struct type to UInt16");
673 	}
674 
convert(UInt32 &)675 	void convert(UInt32&) const
676 	{
677 		throw BadCastException("Cannot cast Struct type to UInt32");
678 	}
679 
convert(UInt64 &)680 	void convert(UInt64&) const
681 	{
682 		throw BadCastException("Cannot cast Struct type to UInt64");
683 	}
684 
convert(bool &)685 	void convert(bool&) const
686 	{
687 		throw BadCastException("Cannot cast Struct type to bool");
688 	}
689 
convert(float &)690 	void convert(float&) const
691 	{
692 		throw BadCastException("Cannot cast Struct type to float");
693 	}
694 
convert(double &)695 	void convert(double&) const
696 	{
697 		throw BadCastException("Cannot cast Struct type to double");
698 	}
699 
convert(char &)700 	void convert(char&) const
701 	{
702 		throw BadCastException("Cannot cast Struct type to char");
703 	}
704 
convert(std::string & val)705 	void convert(std::string& val) const
706 	{
707 		val.append("{ ");
708 		ValueType::ConstIterator it = _val.begin();
709 		ValueType::ConstIterator itEnd = _val.end();
710 		if (!_val.empty())
711 		{
712 			Var key(it->first);
713 			Impl::appendJSONKey(val, key);
714 			val.append(" : ");
715 			Impl::appendJSONValue(val, it->second);
716 			++it;
717 		}
718 		for (; it != itEnd; ++it)
719 		{
720 			val.append(", ");
721 			Var key(it->first);
722 			Impl::appendJSONKey(val, key);
723 			val.append(" : ");
724 			Impl::appendJSONValue(val, it->second);
725 		}
726 		val.append(" }");
727 	}
728 
convert(Poco::DateTime &)729 	void convert(Poco::DateTime&) const
730 	{
731 		throw BadCastException("Struct -> Poco::DateTime");
732 	}
733 
convert(Poco::LocalDateTime &)734 	void convert(Poco::LocalDateTime&) const
735 	{
736 		throw BadCastException("Struct -> Poco::LocalDateTime");
737 	}
738 
convert(Poco::Timestamp &)739 	void convert(Poco::Timestamp&) const
740 	{
741 		throw BadCastException("Struct -> Poco::Timestamp");
742 	}
743 
744 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
745 	{
746 		return cloneHolder(pVarHolder, _val);
747 	}
748 
value()749 	const ValueType& value() const
750 	{
751 		return _val;
752 	}
753 
isArray()754 	bool isArray() const
755 	{
756 		return false;
757 	}
758 
isStruct()759 	bool isStruct() const
760 	{
761 		return true;
762 	}
763 
isOrdered()764 	bool isOrdered() const
765 	{
766 		return true;
767 	}
768 
isInteger()769 	bool isInteger() const
770 	{
771 		return false;
772 	}
773 
isSigned()774 	bool isSigned() const
775 	{
776 		return false;
777 	}
778 
isNumeric()779 	bool isNumeric() const
780 	{
781 		return false;
782 	}
783 
isString()784 	bool isString() const
785 	{
786 		return false;
787 	}
788 
size()789 	std::size_t size() const
790 	{
791 		return _val.size();
792 	}
793 
794 	Var& operator [] (const KeyType& name)
795 	{
796 		return _val[name];
797 	}
798 
799 	const Var& operator [] (const KeyType& name) const
800 	{
801 		return _val[name];
802 	}
803 
804 private:
805 	ValueType _val;
806 };
807 
808 
809 template <>
810 class VarHolderImpl<Struct<int, Poco::OrderedMap<int, Var>, Poco::OrderedSet<int>>> : public VarHolder
811 {
812 public:
813 	typedef int KeyType;
814 	typedef Poco::OrderedMap<KeyType, Var> MapType;
815 	typedef Poco::OrderedSet<KeyType> SetType;
816 	typedef Struct<KeyType, MapType, SetType> ValueType;
817 
VarHolderImpl(const ValueType & val)818 	VarHolderImpl(const ValueType& val) : _val(val)
819 	{
820 	}
821 
~VarHolderImpl()822 	~VarHolderImpl()
823 	{
824 	}
825 
type()826 	const std::type_info& type() const
827 	{
828 		return typeid(ValueType);
829 	}
830 
convert(Int8 &)831 	void convert(Int8&) const
832 	{
833 		throw BadCastException("Cannot cast Struct type to Int8");
834 	}
835 
convert(Int16 &)836 	void convert(Int16&) const
837 	{
838 		throw BadCastException("Cannot cast Struct type to Int16");
839 	}
840 
convert(Int32 &)841 	void convert(Int32&) const
842 	{
843 		throw BadCastException("Cannot cast Struct type to Int32");
844 	}
845 
convert(Int64 &)846 	void convert(Int64&) const
847 	{
848 		throw BadCastException("Cannot cast Struct type to Int64");
849 	}
850 
convert(UInt8 &)851 	void convert(UInt8&) const
852 	{
853 		throw BadCastException("Cannot cast Struct type to UInt8");
854 	}
855 
convert(UInt16 &)856 	void convert(UInt16&) const
857 	{
858 		throw BadCastException("Cannot cast Struct type to UInt16");
859 	}
860 
convert(UInt32 &)861 	void convert(UInt32&) const
862 	{
863 		throw BadCastException("Cannot cast Struct type to UInt32");
864 	}
865 
convert(UInt64 &)866 	void convert(UInt64&) const
867 	{
868 		throw BadCastException("Cannot cast Struct type to UInt64");
869 	}
870 
convert(bool &)871 	void convert(bool&) const
872 	{
873 		throw BadCastException("Cannot cast Struct type to bool");
874 	}
875 
convert(float &)876 	void convert(float&) const
877 	{
878 		throw BadCastException("Cannot cast Struct type to float");
879 	}
880 
convert(double &)881 	void convert(double&) const
882 	{
883 		throw BadCastException("Cannot cast Struct type to double");
884 	}
885 
convert(char &)886 	void convert(char&) const
887 	{
888 		throw BadCastException("Cannot cast Struct type to char");
889 	}
890 
convert(std::string & val)891 	void convert(std::string& val) const
892 	{
893 		val.append("{ ");
894 		ValueType::ConstIterator it = _val.begin();
895 		ValueType::ConstIterator itEnd = _val.end();
896 		if (!_val.empty())
897 		{
898 			Var key(it->first);
899 			Impl::appendJSONKey(val, key);
900 			val.append(" : ");
901 			Impl::appendJSONValue(val, it->second);
902 			++it;
903 		}
904 		for (; it != itEnd; ++it)
905 		{
906 			val.append(", ");
907 			Var key(it->first);
908 			Impl::appendJSONKey(val, key);
909 			val.append(" : ");
910 			Impl::appendJSONValue(val, it->second);
911 		}
912 		val.append(" }");
913 	}
914 
convert(Poco::DateTime &)915 	void convert(Poco::DateTime&) const
916 	{
917 		throw BadCastException("Struct -> Poco::DateTime");
918 	}
919 
convert(Poco::LocalDateTime &)920 	void convert(Poco::LocalDateTime&) const
921 	{
922 		throw BadCastException("Struct -> Poco::LocalDateTime");
923 	}
924 
convert(Poco::Timestamp &)925 	void convert(Poco::Timestamp&) const
926 	{
927 		throw BadCastException("Struct -> Poco::Timestamp");
928 	}
929 
930 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
931 	{
932 		return cloneHolder(pVarHolder, _val);
933 	}
934 
value()935 	const ValueType& value() const
936 	{
937 		return _val;
938 	}
939 
isArray()940 	bool isArray() const
941 	{
942 		return false;
943 	}
944 
isStruct()945 	bool isStruct() const
946 	{
947 		return true;
948 	}
949 
isOrdered()950 	bool isOrdered() const
951 	{
952 		return true;
953 	}
954 
isInteger()955 	bool isInteger() const
956 	{
957 		return false;
958 	}
959 
isSigned()960 	bool isSigned() const
961 	{
962 		return false;
963 	}
964 
isNumeric()965 	bool isNumeric() const
966 	{
967 		return false;
968 	}
969 
isString()970 	bool isString() const
971 	{
972 		return false;
973 	}
974 
size()975 	std::size_t size() const
976 	{
977 		return _val.size();
978 	}
979 
980 	Var& operator [] (const KeyType& name)
981 	{
982 		return _val[name];
983 	}
984 
985 	const Var& operator [] (const KeyType& name) const
986 	{
987 		return _val[name];
988 	}
989 
990 private:
991 	ValueType _val;
992 };
993 
994 
995 } // namespace Dynamic
996 
997 
998 typedef Dynamic::Struct<std::string> DynamicStruct;
999 typedef Dynamic::Struct<std::string, Poco::OrderedMap<std::string, Dynamic::Var>, Poco::OrderedSet<std::string>> OrderedDynamicStruct;
1000 
1001 
1002 } // namespace Poco
1003 
1004 
1005 #endif // Foundation_Struct_INCLUDED
1006