00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _WX_DOCVIEWXMLIO_H_
00019 #define _WX_DOCVIEWXMLIO_H_
00020
00021 #include "docviewprivate.h"
00022
00023 #if wxART2D_USE_XMLPARSE
00024
00025 #include <wx/defs.h>
00026 #include <wx/string.h>
00027
00028 #include <expat.h>
00029
00030 #include "wx/general/genmod.h"
00031
00032
00033
00034
00035
00036 class a2dIOHandlerXMLException
00037 {
00038
00039 public:
00040
00041 a2dIOHandlerXMLException( const wxString& exMessage): m_message(exMessage) {}
00042
00043
00044 a2dIOHandlerXMLException( const wxString& exMessage, int exRow, int exColumn)
00045 : m_message(exMessage), m_row(exRow), m_column(exColumn) {}
00046
00047
00048 a2dIOHandlerXMLException( const a2dIOHandlerXMLException& other)
00049 { m_message = other.m_message; }
00050
00051 a2dIOHandlerXMLException& operator=(const a2dIOHandlerXMLException& other)
00052 {
00053 if (&other != this) {
00054 m_message = other.m_message;
00055 }
00056
00057 return *this;
00058 }
00059
00060 virtual ~a2dIOHandlerXMLException() {}
00061
00062 int getLineNumber() const { return m_row; }
00063 int getColumnNumber() const { return m_column; }
00064
00065 wxString getMessage() const { return m_message; }
00066 void setMessage( const wxString& exMessage) { m_message = exMessage; }
00067
00068 protected:
00069
00070 wxString m_message;
00071 int m_row;
00072 int m_column;
00073 };
00074
00075
00076
00077
00078
00079 enum XMLeventType
00080 {
00081 START_DOCUMENT,
00082 END_DOCUMENT,
00083 START_TAG,
00084 END_TAG,
00085 CONTENT
00086 };
00087
00088
00089 wxString GetTypeString(const XMLeventType& type);
00090
00091 #include <wx/variant.h>
00092
00093
00094
00095
00096
00097 class A2DGENERALDLLEXP a2dAttributeHash;
00098 class A2DGENERALDLLEXP a2dAttributeHash_wxImplementation_HashTable;
00099 class A2DGENERALDLLEXP a2dAttributeHash_wxImplementation_KeyEx;
00100 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, a2dAttributeHash, class A2DGENERALDLLEXP );
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 class A2DGENERALDLLEXP a2dXMLTag : public a2dObject
00111 {
00112 public:
00113
00114
00115
00116
00117
00118
00119
00120 a2dXMLTag( XMLeventType type, wxString tagname = wxT("") );
00121
00122
00123
00124
00125
00126 a2dXMLTag(const a2dXMLTag& tag);
00127
00128
00129 ~a2dXMLTag();
00130
00131
00132 virtual a2dObject* Clone( CloneOptions options ) const;
00133
00134 wxString GetName() const { return m_tag; }
00135
00136 bool SetAttribute( const wxString& attributeName, const wxString& Value );
00137
00138 wxString* GetAttribute( const wxString& attributeName );
00139
00140 #if wxART2D_USE_CVGIO
00141 virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
00142 virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
00143 #endif //wxART2D_USE_CVGIO
00144
00145
00146 wxString m_tag;
00147
00148
00149 wxString m_text;
00150
00151
00152 XMLeventType m_type;
00153
00154 int m_line;
00155
00156 int m_column;
00157
00158
00159 bool m_hasContent;
00160
00161
00162 bool m_hasattributes;
00163
00164 a2dAttributeHash m_attributes;
00165 };
00166
00167 #if (defined(__WXMSW__) && defined(WXUSINGDLL) )
00168 template class A2DGENERALDLLEXP a2dSmrtPtr<a2dXMLTag>;
00169 template class A2DGENERALDLLEXP std::allocator<class a2dSmrtPtr<class a2dXMLTag> >;
00170 template class A2DGENERALDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dXMLTag>, std::allocator<class a2dSmrtPtr<class a2dXMLTag> > >::_Node >;
00171 template class A2DGENERALDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dXMLTag>, std::allocator<class a2dSmrtPtr<class a2dXMLTag> > >::_Nodeptr >;
00172 template class A2DGENERALDLLEXP std::list<class a2dSmrtPtr<class a2dXMLTag> >;
00173 template class A2DGENERALDLLEXP a2dlist<class a2dSmrtPtr<class a2dXMLTag> >;
00174 template class A2DGENERALDLLEXP a2dSmrtPtrList< a2dXMLTag >;
00175 #endif
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 class A2DGENERALDLLEXP a2dIOHandlerXML : public a2dIOHandlerStrIn
00194 {
00195 public:
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 a2dIOHandlerXML();
00210
00211
00212 ~a2dIOHandlerXML();
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 virtual void InitializeLoad( );
00224
00225
00226 virtual void ResetLoad();
00227
00228
00229 XML_Parser& GetXMLParser() { return m_parser; };
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 virtual int GetCurrentColumnNumber();
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 virtual int GetCurrentLineNumber();
00252
00253
00254 wxString GetErrorString();
00255
00256 double ParseDouble( const wxString& buffer, unsigned int& position ) ;
00257 void SkipCommaSpaces( const wxString& buffer, unsigned int& position );
00258 void SkipSpaces( const wxString& buffer, unsigned int& position );
00259
00260 protected:
00261
00262 virtual void StartElementHnd( a2dXMLTag* WXUNUSED(tag) ) {}
00263 virtual void EndElementHnd( const wxString& WXUNUSED(name) ) {}
00264 virtual void CharacterDataHnd( const wxString& WXUNUSED(text) ) {}
00265 virtual void CommentHnd( const wxString& WXUNUSED(comment) ) {}
00266 virtual void DefaultHnd( const wxString& WXUNUSED(def) ) {}
00267
00268
00269 static void BaseStartElementHnd(void *userData, const char* name, const char** atts);
00270 static void BaseEndElementHnd(void *userData, const char* name);
00271 static void BaseCharacterDataHnd(void *userData, const char* s, int len);
00272 static void BaseCommentHnd(void *userData, const char* data);
00273 static void BaseDefaultHnd(void *userData, const char* s, int len);
00274
00275
00276 XML_Parser m_parser;
00277
00278
00279 char* m_buffer;
00280
00281
00282 bool m_done;
00283
00284 static wxString m_encoding;
00285
00286 static wxString m_version;
00287 };
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 class A2DGENERALDLLEXP a2dIOHandlerXMLPull : public a2dIOHandlerXML
00305 {
00306 public:
00307
00308
00309
00310
00311 a2dIOHandlerXMLPull();
00312
00313
00314 ~a2dIOHandlerXMLPull();
00315
00316
00317 a2dXMLTag* GetCurrentTag() { return m_current; }
00318
00319
00320
00321
00322
00323 virtual void InitializeLoad( );
00324
00325
00326 virtual void ResetLoad();
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 void Require( const XMLeventType& type, wxString name);
00339
00340
00341
00342
00343
00344
00345
00346 wxString GetTagName();
00347
00348
00349
00350
00351
00352
00353
00354 wxString GetContent();
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 XMLeventType GetEventType();
00370
00371
00372 int GetDepth() { return m_depth; }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 XMLeventType NextTag();
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 XMLeventType Next();
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 wxString GetAttributeValue( const wxString& attrib, const wxString& defaultv = wxT("") );
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 wxString RequireAttributeValue( const wxString& attrib );
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 double GetAttributeValueDouble( const wxString& attrib, double defaultv = 0 );
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 double RequireAttributeValueDouble( const wxString& attrib );
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 int GetAttributeValueInt( const wxString& attrib, int defaultv = 0 );
00456
00457
00458 inline wxUint16 GetAttributeValueUint16( const wxString& attrib, wxUint16 defaultv = 0 )
00459 { return (wxUint16) GetAttributeValueInt( attrib, (int) defaultv ); }
00460
00461
00462 inline wxUint32 GetAttributeValueUint32( const wxString& attrib, wxUint32 defaultv = 0 )
00463 { return (wxUint32) GetAttributeValueLong( attrib, (long) defaultv ); }
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 int RequireAttributeValueInt( const wxString& attrib );
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 long GetAttributeValueLong( const wxString& attrib, long defaultv = 0 );
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 long RequireAttributeValueLong( const wxString& attrib );
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 bool GetAttributeValueBool( const wxString& attrib, bool defaultv = false );
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 bool RequireAttributeValueBool( const wxString& attrib );
00523
00524
00525 bool HasAttribute( const wxString& attrib );
00526
00527
00528 void SkipSubTree();
00529
00530
00531 virtual int GetCurrentColumnNumber();
00532
00533
00534 virtual int GetCurrentLineNumber();
00535
00536 protected:
00537
00538 virtual void StartElementHnd( a2dXMLTag* tag );
00539 virtual void EndElementHnd( const wxString& name );
00540 virtual void CharacterDataHnd( const wxString& text );
00541 virtual void CommentHnd( const wxString& comment );
00542 virtual void DefaultHnd( const wxString& def );
00543
00544
00545 void FillQueue();
00546
00547
00548 a2dSmrtPtrList<a2dXMLTag> m_elements;
00549
00550 int m_depth;
00551
00552 a2dXMLTag* m_startdoc;
00553 a2dXMLTag* m_enddoc;
00554
00555
00556 a2dXMLTag* m_current;
00557 };
00558
00559
00560
00561
00562
00563 class A2DGENERALDLLEXP a2dIOHandlerXMLWrite : public a2dIOHandlerStrOut
00564 {
00565 public:
00566
00567
00568
00569 a2dIOHandlerXMLWrite();
00570
00571
00572 ~a2dIOHandlerXMLWrite();
00573
00574
00575
00576
00577
00578 virtual void InitializeSave( );
00579
00580
00581 virtual void ResetSave();
00582
00583
00584
00585
00586 int GetDepth() { return m_depth; }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600 void EndlWriteString( const wxString& string );
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 void WriteStartDocument( const wxString& version, const wxString& encoding, bool standalone );
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 void WriteEndDocument();
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641 void WriteStartElement( const wxString& name, bool newLine = true );
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655 void WriteStartElementAttributes( const wxString& name, bool newLine = true );
00656
00657
00658 void WriteStartElement( const a2dXMLTag& tag, bool newLine = true );
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 void WriteElement( const wxString& name, const wxString& content = wxT(""), bool newLine = true );
00670
00671
00672
00673 template<typename w_TypeRef>
00674 void WriteAttribute(const wxString& name, const w_TypeRef & value)
00675 {
00676 wxString error = wxT("Wrong start tag") + this->m_current->m_tag;
00677 wxASSERT_MSG( this->m_current->m_hasattributes , error );
00678 *this << wxT(" ") << name << wxT("=\"") << value << wxT("\"");
00679 }
00680
00681 void WriteAttribute(const wxString& name, const size_t & value)
00682 {
00683 wxString error = wxT("Wrong start tag") + this->m_current->m_tag;
00684 wxASSERT_MSG( this->m_current->m_hasattributes , error );
00685 *this << wxT(" ") << name << wxT("=\"") << (wxUint32) value << wxT("\"");
00686 }
00687
00688 void WriteAttributeEnt( const wxString& name, const wxString& value );
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 void WriteAttribute( const wxString& name, bool value, bool onlyIfTrue = false );
00701
00702
00703 void WriteAttribute( const a2dNamedProperty& attribute );
00704
00705
00706
00707
00708
00709
00710 void WriteEndAttributes(bool close = false);
00711
00712
00713
00714
00715
00716
00717 void WriteEndElement( bool newLine = true );
00718
00719
00720
00721
00722
00723 void WriteContent( const wxString& content );
00724
00725
00726 void WriteNewLine();
00727
00728
00729 void SetIndentSize( int size ) { m_indentSize = size; }
00730
00731 virtual int GetCurrentColumnNumber();
00732
00733 virtual int GetCurrentLineNumber();
00734
00735 void XmlEncodeStringToStream( const wxChar *string, size_t len = wxString::npos );
00736
00737
00738 void SetFormat( const wxString& format ) { m_format = format; }
00739
00740
00741 virtual void WriteDouble(double d)
00742 {
00743 wxString str;
00744 str.Printf( m_format.c_str(), d);
00745 WriteString(str);
00746 }
00747
00748 void WriteStringEnt(const wxString& string );
00749
00750 a2dIOHandlerXMLWrite& operator<<(const wxInt16 & c);
00751 a2dIOHandlerXMLWrite& operator<<(const wxInt32 & c);
00752 a2dIOHandlerXMLWrite& operator<<(const wxInt64 & c);
00753 a2dIOHandlerXMLWrite& operator<<(const wxUint16 & c);
00754 a2dIOHandlerXMLWrite& operator<<(const wxUint32 & c);
00755 a2dIOHandlerXMLWrite& operator<<(const wxUint64 & c);
00756 a2dIOHandlerXMLWrite& operator<<(const double & f);
00757 a2dIOHandlerXMLWrite& operator<<(const float & f);
00758
00759 a2dIOHandlerXMLWrite& operator<<(const wxChar *string);
00760 a2dIOHandlerXMLWrite& operator<<(const wxString& string);
00761 a2dIOHandlerXMLWrite& operator<<(char c);
00762 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
00763 a2dIOHandlerXMLWrite& operator<<(wchar_t wc);
00764 #endif // wxUSE_UNICODE
00765
00766 protected:
00767
00768 wxString m_format;
00769
00770 void WriteIndent();
00771
00772 int m_indent;
00773
00774 int m_indentSize;
00775
00776 int m_depth;
00777
00778
00779 a2dSmrtPtrList<a2dXMLTag> m_elements;
00780
00781 a2dXMLTag* m_startdoc;
00782 a2dXMLTag* m_enddoc;
00783
00784
00785 a2dXMLTag* m_current;
00786 };
00787
00788 #if wxART2D_USE_CVGIO
00789
00790
00791
00792
00793 class A2DGENERALDLLEXP a2dIOHandlerXmlSerIn : public a2dIOHandlerXMLPull
00794 {
00795 public:
00796
00797 a2dIOHandlerXmlSerIn();
00798
00799
00800 ~a2dIOHandlerXmlSerIn();
00801
00802
00803 bool CanLoad(a2dDocumentInputStream& stream, const wxObject* obj, wxClassInfo* docClassInfo = NULL );
00804
00805
00806
00807
00808
00809
00810
00811
00812 virtual bool Load( a2dDocumentInputStream& stream , wxObject* doc );
00813
00814 protected:
00815
00816
00817 wxObject* m_doc;
00818
00819 };
00820
00821
00822
00823
00824
00825 class A2DGENERALDLLEXP a2dIOHandlerXmlSerOut : public a2dIOHandlerXMLWrite
00826 {
00827 public:
00828
00829 a2dIOHandlerXmlSerOut();
00830
00831
00832 ~a2dIOHandlerXmlSerOut();
00833
00834
00835 bool CanSave( const wxObject* obj = NULL ) { return true; }
00836
00837
00838 virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
00839
00840 protected:
00841
00842
00843 wxObject* m_doc;
00844
00845 };
00846 #endif //wxART2D_USE_CVGIO
00847
00848
00849
00850
00851
00852 class A2DGENERALDLLEXP a2dXmlString : public a2dIOHandlerXMLWrite
00853 {
00854 public:
00855
00856 a2dXmlString( const wxString& str = wxT("") );
00857
00858
00859 ~a2dXmlString();
00860
00861 virtual void Reset();
00862
00863
00864
00865
00866
00867
00868 void WriteCommand( const wxString& name, bool close = true );
00869
00870 #if wxUSE_STD_IOSTREAM
00871 const wxString& GetString() const
00872 {
00873 static wxString aap = wxString( m_strstream.str().c_str(), wxConvUTF8 );
00874 return aap;
00875 }
00876 #else
00877 const wxString GetString() const { return m_strstream.GetString(); }
00878 #endif
00879
00880
00881 bool CanSave( const wxObject* obj = NULL ) { return true; }
00882
00883
00884 virtual bool Save( a2dDocumentOutputStream& WXUNUSED(stream), const wxObject* WXUNUSED(doc) ) { return true; }
00885
00886 protected:
00887
00888 a2dDocumentStringOutputStream m_strstream;
00889 };
00890
00891
00892 #endif // wxART2D_USE_XMLPARSE
00893
00894 #endif
00895