1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
|
/***************************************************************
* Name: XmlSerializer.h
* Purpose: Defines XML serializer and related classes
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-08-28
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _XSXMLSERIALIZE_H
#define _XSXMLSERIALIZE_H
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/wxxmlserializer/PropertyIO.h>
#include <wx/xml/xml.h>
#include <wx/hashmap.h>
#define xsWITH_ROOT true
#define xsWITHOUT_ROOT false
#define xsRECURSIVE true
#define xsNORECURSIVE false
/*! \brief Macro creates new serialized STRING property */
#define XS_SERIALIZE_STRING(x, name) XS_SERIALIZE_PROPERTY(x, wxT("string"), name);
/*! \brief Macro creates new serialized STRING property with defined default value */
#define XS_SERIALIZE_STRING_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("string"), name, def);
/*! \brief Macro creates new serialized STRING property */
#define XS_SERIALIZE_CHAR(x, name) XS_SERIALIZE_PROPERTY(x, wxT("char"), name);
/*! \brief Macro creates new serialized STRING property with defined default value */
#define XS_SERIALIZE_CHAR_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("char"), name, def);
/*! \brief Macro creates new serialized LONG property */
#define XS_SERIALIZE_LONG(x, name) XS_SERIALIZE_PROPERTY(x, wxT("long"), name);
/*! \brief Macro creates new serialized LONG property with defined default value */
#define XS_SERIALIZE_LONG_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("long"), name, xsLongPropIO::ToString(def));
/*! \brief Macro creates new serialized DOUBLE property */
#define XS_SERIALIZE_DOUBLE(x, name) XS_SERIALIZE_PROPERTY(x, wxT("double"), name);
/*! \brief Macro creates new serialized DOUBLE property with defined default value */
#define XS_SERIALIZE_DOUBLE_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("double"), name, xsDoublePropIO::ToString(def));
/*! \brief Macro creates new serialized INT property */
#define XS_SERIALIZE_INT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("int"), name);
/*! \brief Macro creates new serialized INT property with defined default value */
#define XS_SERIALIZE_INT_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("int"), name, xsIntPropIO::ToString(def));
/*! \brief Macro creates new serialized FLOAT property */
#define XS_SERIALIZE_FLOAT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("float"), name);
/*! \brief Macro creates new serialized FLOAT property with defined default value */
#define XS_SERIALIZE_FLOAT_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("float"), name, xsFloatPropIO::ToString(def));
/*! \brief Macro creates new serialized BOOL property */
#define XS_SERIALIZE_BOOL(x, name) XS_SERIALIZE_PROPERTY(x, wxT("bool"), name);
/*! \brief Macro creates new serialized BOOL property with defined default value */
#define XS_SERIALIZE_BOOL_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("bool"), name, xsBoolPropIO::ToString(def));
/*! \brief Macro creates new serialized wxPoint property */
#define XS_SERIALIZE_POINT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("point"), name);
/*! \brief Macro creates new serialized wxPoint property with defined default value */
#define XS_SERIALIZE_POINT_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("point"), name, xsPointPropIO::ToString(def));
/*! \brief Macro creates new serialized wxRealPoint property */
#define XS_SERIALIZE_REALPOINT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("realpoint"), name);
/*! \brief Macro creates new serialized wxRealPoint property with defined default value */
#define XS_SERIALIZE_REALPOINT_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("realpoint"), name, xsRealPointPropIO::ToString(def));
/*! \brief Macro creates new serialized wxSize property */
#define XS_SERIALIZE_SIZE(x, name) XS_SERIALIZE_PROPERTY(x, wxT("size"), name);
/*! \brief Macro creates new serialized wxSize property with defined default value */
#define XS_SERIALIZE_SIZE_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("size"), name, xsSizePropIO::ToString(def));
/*! \brief Macro creates new serialized wxColour property */
#define XS_SERIALIZE_COLOUR(x, name) XS_SERIALIZE_PROPERTY(x, wxT("colour"), name);
/*! \brief Macro creates new serialized wxColour property with defined default value */
#define XS_SERIALIZE_COLOUR_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("colour"), name, xsColourPropIO::ToString(def));
/*! \brief Macro creates new serialized wxPen property */
#define XS_SERIALIZE_PEN(x, name) XS_SERIALIZE_PROPERTY(x, wxT("pen"), name);
/*! \brief Macro creates new serialized wxPen property with defined default value */
#define XS_SERIALIZE_PEN_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("pen"), name, xsPenPropIO::ToString(def));
/*! \brief Macro creates new serialized wxBrush property */
#define XS_SERIALIZE_BRUSH(x, name) XS_SERIALIZE_PROPERTY(x, wxT("brush"), name);
/*! \brief Macro creates new serialized wxBrush property with defined default value */
#define XS_SERIALIZE_BRUSH_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("brush"), name, xsBrushPropIO::ToString(def));
/*! \brief Macro creates new serialized wxFont property */
#define XS_SERIALIZE_FONT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("font"), name);
/*! \brief Macro creates new serialized wxFont property with defined default value */
#define XS_SERIALIZE_FONT_EX(x, name, def) XS_SERIALIZE_PROPERTY_EX(x, wxT("font"), name, xsFontPropIO::ToString(def));
/*! \brief Macro creates new serialized property (type 'array of strings (wxArrayString)') */
#define XS_SERIALIZE_ARRAYSTRING(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arraystring"), name);
/*! \brief Macro creates new serialized property (type 'array of chars (CharArray)') */
#define XS_SERIALIZE_ARRAYCHAR(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arraychar"), name);
/*! \brief Macro creates new serialized property (type 'array of ints (IntArray)') */
#define XS_SERIALIZE_ARRAYINT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arrayint"), name);
/*! \brief Macro creates new serialized property (type 'array of longs (LongArray)') */
#define XS_SERIALIZE_ARRAYLONG(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arraylong"), name);
/*! \brief Macro creates new serialized property (type 'array of doubles (DoubleArray)') */
#define XS_SERIALIZE_ARRAYDOUBLE(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arraydouble"), name);
/*! \brief Macro creates new serialized property (type 'array of wxRealPoint objects') */
#define XS_SERIALIZE_ARRAYREALPOINT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("arrayrealpoint"), name);
/*! \brief Macro creates new serialized property (type 'list of wxRealPoint objects') */
#define XS_SERIALIZE_LISTREALPOINT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("listrealpoint"), name);
/*! \brief Macro creates new serialized property (type 'list of xsSerializable objects') */
#define XS_SERIALIZE_LISTSERIALIZABLE(x, name) XS_SERIALIZE_PROPERTY(x, wxT("listserializable"), name);
/*! \brief Macro creates new serialized property (type 'string hash map (StringMap)') */
#define XS_SERIALIZE_MAPSTRING(x, name) XS_SERIALIZE_PROPERTY(x, wxT("mapstring"), name);
/*! \brief Macro creates new serialized property encapsulating a dynamic serializable object */
#define XS_SERIALIZE_DYNAMIC_OBJECT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("serializabledynamic"), name);
/*! \brief Macro creates new serialized property encapsulating a dynamic serializable object */
#define XS_SERIALIZE_DYNAMIC_OBJECT_NO_CREATE(x, name) XS_SERIALIZE_PROPERTY(x, wxT("serializabledynamicnocreate"), name);
/*! \brief Macro creates new serialized property encapsulating a static serializable object */
#define XS_SERIALIZE_STATIC_OBJECT(x, name) XS_SERIALIZE_PROPERTY(x, wxT("serializablestatic"), name);
/*! \brief Macro creates new serialized property of given type */
#define XS_SERIALIZE_PROPERTY(x, type, name) AddProperty(new xsProperty(&x, type, name));
/*! \brief Macro creates new serialized property of given type with defined dafult value */
#define XS_SERIALIZE_PROPERTY_EX(x, type, name, def) AddProperty(new xsProperty(&x, type, name, def));
/*! \brief Macro creates new serialized property and automaticaly determines its type (if supported) */
#define XS_SERIALIZE(x, name) AddProperty(new xsProperty(&x, name));
/*! \brief Macro creates new serialized property with defined dafult value and automaticaly determines its type (if supported)*/
#define XS_SERIALIZE_EX(x, name, def) AddProperty(new xsProperty(&x, name, def));
/*! \brief Macro registers new IO handler for specified data type (handler class must exist) */
#define XS_REGISTER_IO_HANDLER(type, class) wxXmlSerializer::m_mapPropertyIOHandlers[type] = new class();
/*! \brief Enable RTTI (the same as DECLARE_DYNAMIC_CLASS) and declare xsSerializable::Clone() function */
#define XS_DECLARE_CLONABLE_CLASS(name) \
public: \
DECLARE_DYNAMIC_CLASS(name) \
virtual wxObject* Clone(); \
/*! \brief Enable RTTI (the same as IMPLEMENT_DYNAMIC_CLASS) and implement xsSerializable::Clone() function */
#define XS_IMPLEMENT_CLONABLE_CLASS(name, base) \
IMPLEMENT_DYNAMIC_CLASS(name, base) \
wxObject* name::Clone() \
{ \
if( m_fClone ) return new name(*this); \
else \
return NULL; \
} \
/*! \brief Enable RTTI (the same as IMPLEMENT_DYNAMIC_CLASS2) and implement xsSerializable::Clone() function */
#define XS_IMPLEMENT_CLONABLE_CLASS2(name, base1, base2) \
IMPLEMENT_DYNAMIC_CLASS2(name, base1, base2) \
wxObject* name::Clone() \
{ \
if( m_fClone ) return new name(*this); \
else \
return NULL; \
} \
class WXDLLIMPEXP_XS xsProperty;
class WXDLLIMPEXP_XS xsSerializable;
class WXDLLIMPEXP_XS wxXmlSerializer;
WX_DECLARE_LIST_WITH_DECL(xsProperty, PropertyList, class WXDLLIMPEXP_XS);
WX_DECLARE_LIST_WITH_DECL(xsSerializable, SerializableList, class WXDLLIMPEXP_XS);
WX_DECLARE_HASH_MAP( long, xsSerializable*, wxIntegerHash, wxIntegerEqual, IDMap );
/*!
* \brief Base class encapsulating object which can be serialized/deserialized to/from
* XML file (disk file or any stream). This class acts as a data container for properties
* (xsProperty class objects) encapsulating serialized class data members.
*
* Class data members which should be serialized must be marked by appropriate macro defined
* in wxXmlSerializer.h header file (it is recommended to mark desired data members in the class constructor).
*
* Instances of this class can be arranged into a list/d-ary tree hierarchy so it can behave like
* powerfull data container. All chained serializable class objects can be handled by class
* member functions or by member functions of wxXmlSerializer class object which should be
* used as their manager (recommended way).
*
* Another built-in (optional) functionality is class instaces' cloning. User can use
* XS_DECLARE_CLONABLE_CLASS and XS_IMPLEMENT_CLONABLE_CLASS macros instead of classic
* DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros which lead to definition of
* xsSerializable::Clone() virtual function used for cloning of current class instance
* via its copy constructor (user must define it manually). Virtual xsSerializble::Clone()
* function is also used by the wxXmlSerializer::CopyItems() function (used by the
* wxXmlSerializer copy constructor).
*/
class WXDLLIMPEXP_XS xsSerializable : public wxObject
{
public:
friend class wxXmlSerializer;
XS_DECLARE_CLONABLE_CLASS(xsSerializable);
enum SEARCHMODE
{
/*! \brief Depth-First-Search algorithm */
searchDFS,
/*! \brief Breadth-First-Search algorithm */
searchBFS
};
/*! \brief Constructor. */
xsSerializable();
/*! \brief Copy constructor. */
xsSerializable(const xsSerializable& obj);
/*! \brief Destructor. */
~xsSerializable();
// public functions
/*!
* \brief Get serializable parent object.
* \return Pointer to serializable parent object if exists, otherwise NULL
*/
inline xsSerializable* GetParent() { return m_pParentItem; }
/*!
* \brief Get parent data manager (instance of wxXmlSerializer).
* \return Pointer to parent data manager if set, otherwise NULL
*/
inline wxXmlSerializer* GetParentManager() { return m_pParentManager; }
/*!
* \brief Get first serializable child object.
* \return Pointer to child object if exists, otherwise NULL
*/
xsSerializable* GetFirstChild();
/*!
* \brief Get first serializable child object of given type.
* \param type Child object type (can be NULL for any type)
* \return Pointer to child object if exists, otherwise NULL
*/
xsSerializable* GetFirstChild(wxClassInfo *type);
/*!
* \brief Get last serializable child object.
* \return Pointer to child object if exists, otherwise NULL
*/
xsSerializable* GetLastChild();
/*!
* \brief Get last serializable child object of given type.
* \param type Child object type (can be NULL for any type)
* \return Pointer to child object if exists, otherwise NULL
*/
xsSerializable* GetLastChild(wxClassInfo *type);
/*!
* \brief Get next serializable sibbling object.
* \return Pointer to sibbling object if exists, otherwise NULL
*/
xsSerializable* GetSibbling();
/*!
* \brief Get next serializable sibbling object of given type.
* \param type Child object type (can be NULL for any type)
* \return Pointer to sibbling object if exists, otherwise NULL
*/
xsSerializable* GetSibbling(wxClassInfo *type);
/*!
* \brief Get child item with given ID if exists.
* \param id ID of searched child item
* \param recursive If TRUE then the child shape will be searched recursivelly
* \return Pointer to first child with given ID if pressent, otherwise NULL
*/
xsSerializable* GetChild(long id, bool recursive = xsNORECURSIVE);
/*!
* \brief Function finds out whether this serializable item has some children.
* \return TRUE if the parent shape has children, otherwise FALSE
*/
inline bool HasChildren() const { return !m_lstChildItems.IsEmpty(); }
/*!
* \brief Get list of children (serializable objects) of this object.
* \return Reference to a list with child serializable objects (can be empty)
*/
inline SerializableList& GetChildrenList() { return m_lstChildItems; }
/*!
* \brief Get children of given type.
* \param type Child object type (if NULL then all children are returned)
* \param list Reference to a list where all found child objects will be appended
*/
void GetChildren(wxClassInfo *type, SerializableList& list);
/*!
* \brief Get all children of given type recursively (i.e. children of children of .... ).
* \param type Get only children of given type (if NULL then all children are returned)
* \param list Reference to a list where all found child objects will be appended
* \param mode Search mode. User can choose Depth-First-Search or Breadth-First-Search algorithm (BFS is default)
* \sa SEARCHMODE
*/
void GetChildrenRecursively(wxClassInfo *type, SerializableList& list, SEARCHMODE mode = searchBFS);
/*!
* \brief Get pointer to list node containing first serializable child object.
*/
inline SerializableList::compatibility_iterator GetFirstChildNode() const { return m_lstChildItems.GetFirst(); }
/*!
* \brief Get pointer to list node containing last serializable child object.
*/
inline SerializableList::compatibility_iterator GetLastChildNode() const { return m_lstChildItems.GetLast(); }
/*!
* \brief Set serializable parent object.
* \param parent Pointer to parent object
*/
inline void SetParent(xsSerializable* parent) { m_pParentItem = parent; }
/*!
* \brief Set parent data manager.
* \param parent Pointer to parent data manager
*/
inline void SetParentManager(wxXmlSerializer* parent) { m_pParentManager = parent; }
/*!
* \brief Add serializable child object to this object.
* \param child Pointer to added child object (must NOT be NULL)
* \return Pointer to to the added child object
*/
xsSerializable* AddChild(xsSerializable* child);
/*!
* \brief Insert serializable child object to this object at given position.
* \param pos Zero-based position
* \param child Pointer to added child object (must NOT be NULL)
* \return Pointer to to the added child object
*/
xsSerializable* InsertChild(size_t pos, xsSerializable* child);
/*!
* \brief Remove serializable child item from this object (the child item will be destroyed).
* \param child Pointer to child item which should be removed
*/
void RemoveChild(xsSerializable *child);
/*!
* \brief Remove all child items (all items will be destroyed).
*/
void RemoveChildren();
/*!
* \brief Assign this object as a child to given parent object.
* \param parent Pointer to new parent object (must NOT be NULL)
*/
void Reparent(xsSerializable* parent);
/*!
* \brief Set ID of this object. Can be used for further objects' handling by
* wxXmlSerializer class (default ID value is -1). This functions should NOT
* be used directly; it is called by wxXmlSerializer object in the case that this
* serializable object is attached to another one (or directly to root node of wxXmlSerializer) by
* wxXmlSerializer::AddItem() member function.
*/
void SetId(long id);
/*!
* \brief Get object ID.
* \return ID value or -1 if the ID hasn't been set yet
*/
inline long GetId() const { return m_nId; }
/*!
* \brief Create new 'object' XML node and serialize all marked class data members (properties) into it.
* \param node Pointer to parent XML node
* \return Pointer to modified parent XML node
*/
wxXmlNode* SerializeObject(wxXmlNode* node);
/*!
* \brief Deserialize marked class data members (properties) from appropriate fields of given
* parent 'object' XML node.
* \param node Pointer to parent 'object' XML node
*/
void DeserializeObject(wxXmlNode* node);
/*!
* \brief Add new property to the property list.
* \param property Pointer to added property object
* \sa xsProperty
*/
void AddProperty(xsProperty* property);
/**
* \brief Remove given property from the property list.
* \param property Pointer to existing property.
* \sa xsProperty, GetProperty()
*/
void RemoveProperty(xsProperty *property);
/*!
* \brief Get serialized property of given name.
* \return Pointer to the property object if exists, otherwise NULL
* \sa xsProperty
*/
xsProperty* GetProperty(const wxString& field);
/*!
* \brief Get reference to properties list.
* \sa xsProperty
*/
inline PropertyList& GetProperties() { return m_lstProperties; }
/*!
* \brief Enable/disable serialization of given property.
* \param field Property name
* \param enab TRUE if the property should be serialized, otherwise FALSE
*/
void EnablePropertySerialization(const wxString& field, bool enab);
/*!
* \brief Returns information whether the given property is serialized or not.
* \param field Name of examined property
*/
bool IsPropertySerialized(const wxString& field);
/*!
* \brief Enable/disable object serialization.
* \param enab TRUE if the object should be serialized, otherwise FALSE
*/
inline void EnableSerialization(bool enab) { m_fSerialize = enab; }
/*!
* \brief Returns information whether the object can be serialized or not.
*/
inline bool IsSerialized() const { return m_fSerialize; }
/*!
* \brief Enable/disable object cloning.
* \param enab TRUE if the object can be cloned, otherwise FALSE
*/
inline void EnableCloning(bool enab) { m_fClone = enab; }
/*!
* \brief Returns information whether the object can be cloned or not.
*/
inline bool IsCloningEnabled() const { return m_fClone; }
// overloaded operators
/*!
* \brief Add serializable child object to this object.
* \param child Pointer to added child object (should NOT be NULL)
* \return Pointer to added object
*/
xsSerializable* operator<<(xsSerializable *child);
protected:
// protected data members
/*! \brief List of serialized properties */
PropertyList m_lstProperties;
/*! \brief List of child objects */
SerializableList m_lstChildItems;
/*! \brief Pointer to parent serializable object */
xsSerializable *m_pParentItem;
/*! \brief Pointer to parent data manager */
wxXmlSerializer *m_pParentManager;
/*! \brief Object serialization flag */
bool m_fSerialize;
/*! \brief Object cloning flag */
bool m_fClone;
/**
* \brief Initialize new child object.
* \param child Pointer to new child object
*/
void InitChild(xsSerializable *child);
// protected virtual functions
/*!
* \brief Serialize stored properties to the given XML node. The serialization
* routine is automatically called by the framework and cares about serialization
* of all defined properties.
*
* Note that default implementation automatically serializes all class data members
* marked by appropriate macros. If some non-standard class member should be serialized as well,
* the source code of derived function implementation can be as in following example.
*
* \param node Pointer to XML node where the property nodes will be appended to
*
* Example code:
* \code
* wxXmlNode* DerivedFrom_xsSerializable::Serialize(wxXmlNode* node)
* {
* if(node)
* {
* // call base class's serialization routine
* node = xsSeralizable::Serialize(node);
*
* // serialize custom property
* xsPropertyIO::AddPropertyNode(node, wxT("some_property_field_name"), wxT("string_repr_of_its_value"));
* }
* // return updated node
* return node;
* }
* \endcode
*/
virtual wxXmlNode* Serialize(wxXmlNode* node);
/*!
* \brief Deserialize object properties from the given XML node. The
* routine is automatically called by the framework and cares about deserialization
* of all defined properties.
*
* Note that default implementation automatically deserializes all class data members
* marked by appropriate macros. If some non-standard class member should be deserialized as well,
* the source code of derived function implementation can be as in following example.
*
* \param node Pointer to a source XML node containig the property nodes
*
* Example code:
* \code
* void DerivedFrom_xsSerializable::Deserialize(wxXmlNode* node)
* {
* // call base class's deserialization rountine (if necessary...)
* xsSerializable::Deserialize(node);
*
* // iterate through all custom property nodes
* wxXmlNode *propNode = node->GetChildren();
* while(propNode)
* {
* if(propNode->GetName() == wxT("some_property_field_name"))
* {
* // read the node content and convert it to a proper data type
* }
* propNode = propNode->GetNext();
* }
* }
* \endcode
*/
virtual void Deserialize(wxXmlNode* node);
private:
/*! \brief Object ID */
long m_nId;
};
/*!
* \brief Class encapsulates a serializable objects' manager which is responsible
* for handling stored serializable objects and their serialization/deserialization
* from/to XML files or streams.
*
* Stored objects can be arranged into a list or d-ary tree structure so this class
* can be used as a container for various application data. Also created XML files
* (root node) can be marked with given version and owner name, so it is possible to
* control a version of saved document.
*
* wxXmlSerializer class contains one instance of xsSerializable object created in the
* class constructor (can be set later via member functions as well). This serializable
* object called 'root object' holds all other inserted serializable objects (in case of
* tree structure it is a topmost tree node, in case of list structure all list items are
* its children). These child object can be handled via xsSerializable and wxXmlSerializer
* classes' member functions.
*
* Another built-in (optional) functionality is class instaces' cloning. User can use
* XS_DECLARE_CLONABLE_CLASS and XS_IMPLEMENT_CLONABLE_CLASS macros instead of classic
* DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros which lead to definition of
* wxXmlSerializer::Clone() virtual function used for cloning of current class instance
* via its copy constructor (user must define it manually).
*/
class WXDLLIMPEXP_XS wxXmlSerializer : public wxObject
{
public:
XS_DECLARE_CLONABLE_CLASS(wxXmlSerializer);
/*! \brief Constructor. */
wxXmlSerializer();
/*!
* \brief User constructor.
* \param owner Owner name
* \param root Name of root node
* \param version File version
*/
wxXmlSerializer(const wxString& owner, const wxString& root, const wxString& version);
/*! \brief Copy constructor. */
wxXmlSerializer(const wxXmlSerializer &obj);
/*! \brief Destructor. */
virtual ~wxXmlSerializer();
// public member data accessors
/*!
* \brief Set owner name.
* \param name Owner name
*/
inline void SetSerializerOwner(const wxString& name) { m_sOwner = name; }
/*!
* \brief Set root name.
* \param name Root name
*/
inline void SetSerializerRootName(const wxString& name) { m_sRootName = name; }
/*!
* \brief Set file version.
* \param name File version
*/
inline void SetSerializerVersion(const wxString& name) { m_sVersion = name; }
/*! \brief Get owner name. */
inline const wxString& GetSerializerOwner() const { return m_sOwner; }
/*! \brief Get name of root node. */
inline const wxString& GetSerializerRootName() const { return m_sRootName; }
/*! \brief Get file version. */
inline const wxString& GetSerializerVersion() const { return m_sVersion; }
/*! \brief Get the library version. */
inline const wxString& GetLibraryVersion() const { return m_sLibraryVersion; }
// public functions
/**
* \brief Get last occured error state/message.
* \return Error message
*/
const wxString& GetErrMessage() const { return m_sErr; }
/*! \brief Get pointer to root serializable object. */
inline xsSerializable* GetRootItem() const { return m_pRoot; }
/*!
* \brief Get serializable object with given ID.
* \param id Object ID
* \return Pointer to serializable object if exists, otherwise NULL
*/
xsSerializable* GetItem(long id);
/*!
* \brief Get items of given class type.
* \param type Class type
* \param list List with matching serializable objects
* \param mode Search mode
* \sa xsSerializable::SEARCHMODE
*/
void GetItems(wxClassInfo* type, SerializableList& list, xsSerializable::SEARCHMODE mode = xsSerializable::searchBFS);
/*!
* \brief Check whether given object is included in the serializer.
* \param object Pointer to checked object
* \return True if the object is included in the serializer, otherwise False
*/
bool Contains(xsSerializable *object) const;
/*!
* \brief Check whether any object of given type is included in the serializer.
* \param type Pointer to class info
* \return True if at least one object of given type is included in the serializer, otherwise False
*/
bool Contains(wxClassInfo *type);
/*!
* \brief Set root item.
* \param root Pointer to root item
*/
void SetRootItem(xsSerializable* root);
/*!
* \brief Replace current stored data with a content stored in given source manager.
*
* For proper functionality all stored data items derived from the xsSerializable class
* MUST implement virtual function xsSerializable::Clone() as well as the copy
* constructor. For more details see the xsSerializable::Clone() function documentation.
* \param src Reference to the source data manager
*/
void CopyItems(const wxXmlSerializer& src);
/*!
* \brief Add serializable object to the serializer.
* \param parentId ID of parent serializable object
* \param item Added serializable object
* \return Pointer to added item
*/
xsSerializable* AddItem(long parentId, xsSerializable* item);
/*!
* \brief Add serializable object to the serializer.
* \param parent Pointer to parent serializable object (if NULL then the object
* is added directly to the root item)
* \param item Added serializable object
* \return Pointer to added item
*/
xsSerializable* AddItem(xsSerializable* parent, xsSerializable* item);
/*!
* \brief Remove serializable object from the serializer (object will be destroyed).
* \param id Object ID
*/
void RemoveItem(long id);
/*!
* \brief Remove serializable object from the serializer (object will be destroyed).
* \param item Pointer to removed object
*/
void RemoveItem(xsSerializable* item);
/*! \brief Remove and destroy all stored serializable objects*/
void RemoveAll();
/*!
* \brief Enable/disable object cloning.
* \param enab TRUE if the object can be cloned, otherwise FALSE
*/
inline void EnableCloning(bool enab) { m_fClone = enab; }
/*!
* \brief Returns information whether the object can be cloned or not.
*/
inline bool IsCloned() const { return m_fClone; }
/*!
* \brief Serialize stored objects to given file.
* \param file Full path to output file
* \param withroot If TRUE then the root item's properties are serialized as well
* \return TRUE on success, otherwise FALSE
*/
virtual bool SerializeToXml(const wxString& file, bool withroot = false);
/*!
* \brief Serialize stored objects to given stream.
* \param outstream Output stream
* \param withroot If TRUE then the root item's properties are serialized as well
* \return TRUE on success, otherwise FALSE
*/
virtual bool SerializeToXml(wxOutputStream& outstream, bool withroot = false);
/*!
* \brief Deserialize objects from given file.
* \param file Full path to input file
* \return TRUE on success, otherwise FALSE
*/
virtual bool DeserializeFromXml(const wxString& file);
/*!
* \brief Deserialize objects from given stream.
* \param instream Input stream
* \return TRUE on success, otherwise FALSE
*/
virtual bool DeserializeFromXml(wxInputStream& instream);
/*!
* \brief Serialize child objects of given parent object (parent object can be optionaly
* serialized as well) to given XML node. The function can be overriden if necessary.
* \param parent Pointer to parent serializable object
* \param node Pointer to output XML node
* \param withparent TRUE if the parent object should be serialized as well
*/
virtual void SerializeObjects(xsSerializable* parent, wxXmlNode* node, bool withparent);
/*!
* \brief Deserialize child objects of given parent object from given XML node.
* The function can be overriden if necessary.
* \param parent Pointer to parent serializable object
* \param node Pointer to input XML node
*/
virtual void DeserializeObjects(xsSerializable* parent, wxXmlNode* node);
/*!
* \brief Get the lowest free object ID
*/
long GetNewId();
/*!
* \brief Find out whether given object ID is already used.
* \param id Object ID
* \return TRUE if the object ID is used, otherwise FALSE
*/
bool IsIdUsed(long id);
/*!
* \brief Get number of occurences of given ID.
* \param id Object ID
* \return Number of ID's occurences
*/
int GetIDCount(long id);
/*!
* \brief Get map of used IDs.
* \return Reference to map where all used IDs are stored
*/
IDMap& GetUsedIDs() { return m_mapUsedIDs; }
/*! \brief Initialize all standard property IO handlers */
void InitializeAllIOHandlers();
/*! \brief Clear all initialized property IO handlers */
void ClearIOHandlers();
/*!
* \brief Get property I/O handler for given datatype.
* \param datatype String ID of data type
* \return Pointer to I/O handler suitable for given data type if exists, otherwise NULL
*/
inline static xsPropertyIO* GetPropertyIOHandler(const wxString& datatype) { return m_mapPropertyIOHandlers[datatype]; }
/*! \brief Map of property IO handlers */
static PropertyIOMap m_mapPropertyIOHandlers;
// overloaded operators
/*!
* \brief Add serializable object to the serializer's root node.
* \param obj Pointer to serializable object
* \return Reference to the serializer
*/
wxXmlSerializer& operator<< (xsSerializable *obj) {
if( obj ) this->AddItem( (xsSerializable*)NULL, obj);
return *this;
}
/*!
* \brief Add serializable objects stored in source serializable list to the serializer's root node.
* \param src Reference to source serializable list
* \return Reference to the serializer
*/
wxXmlSerializer& operator<< (SerializableList &src) {
for( SerializableList::iterator it = src.begin(); it != src.end(); ++it )
this->AddItem( (xsSerializable*)NULL, *it);
return *this;
}
/*!
* \brief Get all items managed by the serializer (note that the items will be stored in given
* target list in a row regardless their original hierarchy).
* \param dest Reference to target serializable list
*/
void operator>> (SerializableList &dest) {
this->GetItems(CLASSINFO(xsSerializable), dest);
}
protected:
// protected data members
/*! \brief Owner name */
wxString m_sOwner;
/*! \brief Root node name */
wxString m_sRootName;
/*! \brief File version */
wxString m_sVersion;
/*! \brief Error message */
wxString m_sErr;
/*! \brief Pointer to root object */
xsSerializable* m_pRoot;
/*! \brief Object cloning flag */
bool m_fClone;
/*! \brief Map storing information which ID is already used */
IDMap m_mapUsedIDs;
private:
// private data members
//int m_nCounter;
static int m_nRefCounter;
static wxString m_sLibraryVersion;
// private functions
/*! \brief Auxiliary function */
xsSerializable* _GetItem(long id, xsSerializable* parent);
/*! \brief Auxiliary function */
bool _Contains(xsSerializable *object, xsSerializable* parent) const;
};
/*!
* \brief Class encapsulates a property stored in a list included inside a parent serializable
* object (class xsSerializable) which is serialized/deserialized to/from XML file. The
* property object type is defined by a string name and is processed by parent xsSerializable class object.
*
* Allowed property data types (keywords) are: 'long', 'double', 'bool', 'string', 'point', 'size',
* 'realpoint', 'colour', 'brush', 'pen', 'font', 'arraystring', 'arrayrealpoint', 'listrealpoint',
* 'listserializable', 'serializabledynamic' and 'serializablestatic'. Only properties of these data types are
* recognized and processed by parent serializable object.
*/
class WXDLLIMPEXP_XS xsProperty : public wxObject
{
public:
DECLARE_DYNAMIC_CLASS(xsProperty);
/*! \brief Default constructor */
xsProperty()
{
m_pSourceVariable = NULL;
m_sDataType = wxT("Undefined");
m_sFieldName = wxT("Undefined");
m_sDefaultValueStr = wxT("");
m_fSerialize = false;
}
/*!
* \brief Constructor
* \param src Pointer to serialized object
* \param type String value describing data type of serialized object
* \param field Property name used in XML files and for property handling
* \param def String representation of default poperty value
*/
xsProperty(void* src, const wxString& type, const wxString& field, const wxString& def = wxT(""))
{
m_pSourceVariable = src;
m_sDataType = type;
m_sFieldName = field;
m_sDefaultValueStr = def;
m_fSerialize = true;
}
/*! \brief Constructor for BOOL property. */
xsProperty(bool* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("bool")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for BOOL property with defined default value. */
xsProperty(bool* src, const wxString& field, bool def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("bool")), m_sDefaultValueStr(xsBoolPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for LONG property. */
xsProperty(long* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("long")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for LONG property with defined default value. */
xsProperty(long* src, const wxString& field, long def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("long")), m_sDefaultValueStr(xsLongPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for INT property. */
xsProperty(int* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("int")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for INT property with defined default value. */
xsProperty(int* src, const wxString& field, int def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("int")), m_sDefaultValueStr(xsIntPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for DOUBLE property. */
xsProperty(double* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("double")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for DOUBLE property with defined default value. */
xsProperty(double* src, const wxString& field, double def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("double")), m_sDefaultValueStr(xsDoublePropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for FLOAT property. */
xsProperty(float* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("float")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for FLOAT property with defined default value. */
xsProperty(float* src, const wxString& field, float def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("float")), m_sDefaultValueStr(xsFloatPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxString property. */
xsProperty(wxString* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("string")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxString property with defined default value. */
xsProperty(wxString* src, const wxString& field, const wxString& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("string")), m_sDefaultValueStr(def), m_fSerialize(true) {;}
/*! \brief Constructor for wxChar property. */
xsProperty(wxChar* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("char")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxChar property with defined default value. */
xsProperty(wxChar* src, const wxString& field, wxChar def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("char")), m_sDefaultValueStr(xsCharPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxPoint property. */
xsProperty(wxPoint* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("point")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxPoint property with defined default value. */
xsProperty(wxPoint* src, const wxString& field, const wxPoint& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("point")), m_sDefaultValueStr(xsPointPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxRealPoint property. */
xsProperty(wxRealPoint* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("realpoint")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxRealPoint property with defined default value. */
xsProperty(wxRealPoint* src, const wxString& field, const wxRealPoint& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("realpoint")), m_sDefaultValueStr(xsRealPointPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxSize property. */
xsProperty(wxSize* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("size")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxSize property with defined default value. */
xsProperty(wxSize* src, const wxString& field, const wxSize& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("size")), m_sDefaultValueStr(xsSizePropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxBrush property. */
xsProperty(wxBrush* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("brush")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxBrush property with defined default value. */
xsProperty(wxBrush* src, const wxString& field, const wxBrush& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("brush")), m_sDefaultValueStr(xsBrushPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxPen property. */
xsProperty(wxPen* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("pen")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxPen property with defined default value. */
xsProperty(wxPen* src, const wxString& field, const wxPen& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("pen")), m_sDefaultValueStr(xsPenPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxFont property. */
xsProperty(wxFont* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("font")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxFont property with defined default value. */
xsProperty(wxFont* src, const wxString& field, const wxFont& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("font")), m_sDefaultValueStr(xsFontPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxColour property. */
xsProperty(wxColour* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("colour")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for wxColour property with defined default value. */
xsProperty(wxColour* src, const wxString& field, const wxColour& def) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("colour")), m_sDefaultValueStr(xsColourPropIO::ToString(def)), m_fSerialize(true) {;}
/*! \brief Constructor for wxArrayString property. */
xsProperty(wxArrayString* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arraystring")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for CharArray property. */
xsProperty(wxXS::CharArray* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arraychar")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for IntArray property. */
xsProperty(wxXS::IntArray* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arrayint")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for LongArray property. */
xsProperty(wxXS::LongArray* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arraylong")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for DoubleArray property. */
xsProperty(wxXS::DoubleArray* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arraydoubles")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for RealPointArray property. */
xsProperty(wxXS::RealPointArray* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("arrayrealpoint")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for RealPointList property. */
xsProperty(wxXS::RealPointList* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("listrealpoint")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for SerializableList property. */
xsProperty(SerializableList* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("listserializable")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for StringMap property. */
xsProperty(wxXS::StringMap* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("mapstring")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for static serializable property. */
xsProperty(xsSerializable* src, const wxString& field) : m_pSourceVariable((void*)src), m_sFieldName(field), m_sDataType(wxT("serializablestatic")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Constructor for dynamic serializable property. */
xsProperty(xsSerializable** src, const wxString& field) : m_pSourceVariable((void**)src), m_sFieldName(field), m_sDataType(wxT("serializabledynamic")), m_sDefaultValueStr(wxT("")), m_fSerialize(true) {;}
/*! \brief Copy constructor. */
xsProperty(const xsProperty& obj) : wxObject( obj ), m_pSourceVariable(obj.m_pSourceVariable), m_sFieldName(obj.m_sFieldName), m_sDataType(obj.m_sDataType), m_sDefaultValueStr(obj.m_sDefaultValueStr), m_fSerialize(obj.m_fSerialize) {;}
~xsProperty(){;}
// public functions
/**
* \brief Convert managed data to wxVariant (supported data types: int, long, bool, double, float,
* wxChar, wxString and wxArrayString).
* \return wxVariant object containing the data
*/
wxVariant ToVariant()
{
if( m_sDataType == wxT("int") ) return wxVariant( *(int*) m_pSourceVariable );
else if( m_sDataType == wxT("long") ) return wxVariant( *(long*) m_pSourceVariable );
else if( m_sDataType == wxT("bool") ) return wxVariant( *(bool*) m_pSourceVariable );
else if( m_sDataType == wxT("double") ) return wxVariant( *(double*) m_pSourceVariable );
else if( m_sDataType == wxT("float") ) return wxVariant( *(float*) m_pSourceVariable );
else if( m_sDataType == wxT("char") ) return wxVariant( *(wxChar*) m_pSourceVariable );
else if( m_sDataType == wxT("string") ) return wxVariant( *(wxString*) m_pSourceVariable );
else if( m_sDataType == wxT("arraystring") ) return wxVariant( *(wxArrayString*) m_pSourceVariable );
else return wxVariant();
}
/**
* \brief Get textual representation of the property's value.
* \return Textual representation of current value
*/
wxString ToString()
{
xsPropertyIO *pIO = wxXmlSerializer::m_mapPropertyIOHandlers[m_sDataType];
if(pIO) return pIO->GetValueStr(this);
else
return wxEmptyString;
}
/**
* \brief Set value defined by its textual representation.
* \param val Textual representation of given value
*/
void FromString(const wxString& val)
{
xsPropertyIO *pIO = wxXmlSerializer::m_mapPropertyIOHandlers[m_sDataType];
if(pIO) pIO->SetValueStr(this, val);
}
/**
* \brief Get reference to managed data member as BOOL.
* \return Reference to managed data member
*/
inline bool& AsBool() { wxASSERT(m_sDataType == wxT("bool")); return *(bool*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as INT.
* \return Reference to managed data member
*/
inline int& AsInt() { wxASSERT(m_sDataType == wxT("int")); return *(int*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as LONG.
* \return Reference to managed data member
*/
inline long& AsLong() { wxASSERT(m_sDataType == wxT("long")); return *(long*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as FLOAT.
* \return Reference to managed data member
*/
inline float& AsFloat() { wxASSERT(m_sDataType == wxT("float")); return *(float*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as DOUBLE.
* \return Reference to managed data member
*/
inline double& AsDouble() { wxASSERT(m_sDataType == wxT("double")); return *(double*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxChar.
* \return Reference to managed data member
*/
inline wxChar& AsChar() { wxASSERT(m_sDataType == wxT("char")); return *(wxChar*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxString.
* \return Reference to managed data member
*/
inline wxString& AsString() { wxASSERT(m_sDataType == wxT("string")); return *(wxString*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxSize.
* \return Reference to managed data member
*/
inline wxSize& AsSize() { wxASSERT(m_sDataType == wxT("size")); return *(wxSize*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxPoint.
* \return Reference to managed data member
*/
inline wxPoint& AsPoint() { wxASSERT(m_sDataType == wxT("point")); return *(wxPoint*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxRealPoint.
* \return Reference to managed data member
*/
inline wxRealPoint& AsRealPoint() { wxASSERT(m_sDataType == wxT("realpoint")); return *(wxRealPoint*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxBrush.
* \return Reference to managed data member
*/
inline wxBrush& AsBrush() { wxASSERT(m_sDataType == wxT("brush")); return *(wxBrush*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxPen.
* \return Reference to managed data member
*/
inline wxPen& AsPen() { wxASSERT(m_sDataType == wxT("pen")); return *(wxPen*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxFont.
* \return Reference to managed data member
*/
inline wxFont& AsFont() { wxASSERT(m_sDataType == wxT("font")); return *(wxFont*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxColour.
* \return Reference to managed data member
*/
inline wxColour& AsColour() { wxASSERT(m_sDataType == wxT("colour")); return *(wxColour*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as wxArrayString.
* \return Reference to managed data member
*/
inline wxArrayString& AsStringArray() { wxASSERT(m_sDataType == wxT("arraystring")); return *(wxArrayString*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as CharArray.
* \return Reference to managed data member
*/
inline wxXS::CharArray& AsCharArray() { wxASSERT(m_sDataType == wxT("arraychar")); return *(wxXS::CharArray*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as IntArray.
* \return Reference to managed data member
*/
inline wxXS::IntArray& AsIntArray() { wxASSERT(m_sDataType == wxT("arrayint")); return *(wxXS::IntArray*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as LongArray.
* \return Reference to managed data member
*/
inline wxXS::LongArray& AsLongArray() { wxASSERT(m_sDataType == wxT("arraylong")); return *(wxXS::LongArray*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as DoubleArray.
* \return Reference to managed data member
*/
inline wxXS::DoubleArray& AsDoubleArray() { wxASSERT(m_sDataType == wxT("arraydouble")); return *(wxXS::DoubleArray*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as RealPointArray.
* \return Reference to managed data member
*/
inline wxXS::RealPointArray& AsRealPointArray() { wxASSERT(m_sDataType == wxT("arrayrealpoint")); return *(wxXS::RealPointArray*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as RealPointList.
* \return Reference to managed data member
*/
inline wxXS::RealPointList& AsRealPointList() { wxASSERT(m_sDataType == wxT("listrealpoint")); return *(wxXS::RealPointList*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as SerializableList.
* \return Reference to managed data member
*/
inline SerializableList& AsSerializableList() { wxASSERT(m_sDataType == wxT("listserializable")); return *(SerializableList*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as StringMap.
* \return Reference to managed data member
*/
inline wxXS::StringMap& AsStringMap() { wxASSERT(m_sDataType == wxT("mapstring")); return *(wxXS::StringMap*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as serializable static object.
* \return Reference to managed data member
*/
inline xsSerializable& AsSerializableStatic() { wxASSERT(m_sDataType == wxT("serializablestatic")); return *(xsSerializable*)m_pSourceVariable; }
/**
* \brief Get reference to managed data member as serializable dynamic object.
* \return Reference to managed data member
*/
inline xsSerializable& AsSerializableDynamic() { wxASSERT(m_sDataType == wxT("serializabledynamic")); return **(xsSerializable**)m_pSourceVariable; }
// public data members
/*! \brief General (void) pointer to serialized object encapsulated by the property */
void* m_pSourceVariable;
/*! \brief Field (property) name */
wxString m_sFieldName;
/*! \brief Data type */
wxString m_sDataType;
/*! \brief String representation of property's default value */
wxString m_sDefaultValueStr;
/*! \brief Flag used for enabling/disabling of property serialization */
bool m_fSerialize;
};
#endif //_XSXMLSERIALIZE_H
|