wxArt2D
genxmlpars.h
Go to the documentation of this file.
1 /*! \file wx/xmlparse/genxmlpars.h
2  \brief - XML I/O classes which is Pull parser based for reading XML files.
3 
4  The serialization of documents is XML based, and streamimg in or out into files is
5  in several format cases also in XML.
6  The classes here integrate the a2dIOHandlerStrIn and a2dIOHandlerStrOut with
7  the XML parsing and XML writing classes.
8  IO in and output for XML based formats do derive from the classes here.
9 
10  \author Probably Klaas Holwerda
11 
12  Copyright: 2001-2004 (C) Probably Klaas Holwerda
13 
14  Licence: wxWidgets licence
15 
16  RCS-ID: $Id: genxmlpars.h,v 1.34 2009/07/15 21:23:43 titato Exp $
17 */
18 #ifndef _WX_DOCVIEWXMLIO_H_
19 #define _WX_DOCVIEWXMLIO_H_
20 
21 #include "wxartbaseprivate.h"
22 
23 #if wxART2D_USE_XMLPARSE
24 
25 #include <wx/defs.h>
26 #include <wx/string.h>
27 
28 #include <expat.h>
29 
30 #include "wx/general/genmod.h"
31 
32 //! For exceptions thrown while parsing XML files
33 /*!
34  \ingroup fileio
35 */
37 {
38 
39 public:
40  //! Constructor.
41  a2dIOHandlerXMLException( const wxString& exMessage ): m_message( exMessage ) {}
42 
43  //! Constructor with row and line params
44  a2dIOHandlerXMLException( const wxString& exMessage, int exRow, int exColumn )
45  : m_message( exMessage ), m_row( exRow ), m_column( exColumn ) {}
46 
47  //! Copy constructor.
49  { m_message = other.m_message; }
50 
51  a2dIOHandlerXMLException& operator=( const a2dIOHandlerXMLException& other )
52  {
53  if ( &other != this )
54  {
55  m_message = other.m_message;
56  }
57 
58  return *this;
59  }
60 
61  virtual ~a2dIOHandlerXMLException() {}
62 
63  int getLineNumber() const { return m_row; }
64  int getColumnNumber() const { return m_column; }
65 
66  wxString getMessage() const { return m_message; }
67  void setMessage( const wxString& exMessage ) { m_message = exMessage; }
68 
69 protected:
70 
71  wxString m_message;
72  int m_row;
73  int m_column;
74 };
75 
76 //! Types of XML events when reading files.
77 /*!
78  \ingroup fileio
79 */
81 {
82  START_DOCUMENT, /*!< Start of document */
83  END_DOCUMENT, /*!< End of document */
84  START_TAG, /*!< Start tag */
85  END_TAG, /*!< End tag */
86  CONTENT /*!< Content between start and end tag */
87 };
88 
89 //! translate XMLeventType to a string
90 wxString GetTypeString( const XMLeventType& type );
91 
92 #include <wx/variant.h>
93 
94 
95 //! wxString keys to hold attributes
96 /*!
97 */
98 class A2DGENERALDLLEXP a2dAttributeHash;
99 class A2DGENERALDLLEXP a2dAttributeHash_wxImplementation_HashTable;
100 class A2DGENERALDLLEXP a2dAttributeHash_wxImplementation_KeyEx;
101 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, a2dAttributeHash, class A2DGENERALDLLEXP );
102 
103 
104 //! used in XML parsing to hold one tag and its atributes
105 /*!
106  The a2dIOHandlerXMLPull and derived classes use this object
107  to parse XML documents.
108 
109  \ingroup fileio
110 */
111 class A2DGENERALDLLEXP a2dXMLTag : public a2dObject
112 {
113 public:
114  //! Constructor.
115  /*!
116  \see XMLeventType
117 
118  \param type the event type
119  \param tagname the tag name
120  */
121  a2dXMLTag( XMLeventType type, wxString tagname = wxT( "" ) );
122 
123  //! Copy constructor.
124  /*!
125  \param tag the original tag
126  */
127  a2dXMLTag( const a2dXMLTag& tag );
128 
129  //! Destructor.
130  ~a2dXMLTag();
131 
132  //! create an exact copy of this property
133  virtual a2dObject* Clone( CloneOptions options ) const;
134 
135  wxString GetName() const { return m_tag; }
136 
137  bool SetAttribute( const wxString& attributeName, const wxString& Value );
138 
139  wxString* GetAttribute( const wxString& attributeName );
140 
141 #if wxART2D_USE_CVGIO
142  virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite );
143  virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts );
144 #endif //wxART2D_USE_CVGIO
145 
146  //! tag name
147  wxString m_tag;
148 
149  //! Content of the tag
150  wxString m_text;
151 
152  //! event type
154 
155  int m_line;
156 
157  int m_column;
158 
159  //! flag to trigger if content was written
161 
162  //! does the current XMLTag have attributes?
164 
165  a2dAttributeHash m_attributes;
166 
167 private:
168  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const { return NULL; }
169 };
170 
171 #if (defined(__WXMSW__) && defined(WXUSINGDLL) )
172 template class A2DGENERALDLLEXP a2dSmrtPtr<a2dXMLTag>;
173 template class A2DGENERALDLLEXP std::allocator<class a2dSmrtPtr<class a2dXMLTag> >;
174 template class A2DGENERALDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dXMLTag>, std::allocator<class a2dSmrtPtr<class a2dXMLTag> > >::_Node >;
175 template class A2DGENERALDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dXMLTag>, std::allocator<class a2dSmrtPtr<class a2dXMLTag> > >::_Nodeptr >;
176 template class A2DGENERALDLLEXP std::list<class a2dSmrtPtr<class a2dXMLTag> >;
177 template class A2DGENERALDLLEXP a2dlist<class a2dSmrtPtr<class a2dXMLTag> >;
178 template class A2DGENERALDLLEXP a2dSmrtPtrList< a2dXMLTag >;
179 #endif
180 
181 
182 //! Input handler for the XML format
183 /*!
184  The a2dIOHandlerXML uses a fast, lightweight, event-driven XML parser (expat).
185 
186  \remark
187  It's only a input handler, the a2dIOHandlerXML is not able to write
188  XML data. Use a2dIOHandlerXMLPull to read and write data.
189  a2dIOHandlerXMLPull also has an comfortable API to read / write data,
190  so there's no need to use the a2dIOHandlerXML class directly if you want
191  to create your own XML fileformat.
192 
193  \see a2dIOHandlerXMLPull
194 
195  \ingroup fileio
196 */
197 class A2DGENERALDLLEXP a2dIOHandlerXML : public a2dIOHandlerStrIn
198 {
199 public:
200  //! Constructor.
201  /*!
202  \remark
203  Before you can use this object you've to call the InitializeLoad()
204  or InitializeSave() method
205 
206  \remark
207  The standard IO handlers of wxArt2d (i.e. wxDocviewIOHandlerXmlSer)
208  call the Initialize method in the Load... methods, an extra call
209  to Initialize is not necessary.
210 
211  \see InitializeLoad
212  */
213  a2dIOHandlerXML();
214 
215  //! Destructor.
216  ~a2dIOHandlerXML();
217 
218  //! Inits the handler for reading
219  /*!
220  This method creates the parser and the buffer and also connects
221  the Base...Hnd methods of this class with the parser.
222 
223  \remark
224  You've to call this method before you can start doing something useful
225  with this object!
226  */
227  virtual void InitializeLoad( );
228 
229  //! Reset the object after loading
230  virtual void ResetLoad();
231 
232  //! Returns the XML parser
233  XML_Parser& GetXMLParser() { return m_parser; };
234 
235  //! Returns the current column no.
236  /*!
237  Returns the current column no. Mainly used for error msgs / debugging,
238  but maybe usefull for other purposes.
239 
240  \see GetCurrentLineNumber
241 
242  \return current column no.
243  */
244  virtual int GetCurrentColumnNumber();
245 
246  //! Returns the current line no.
247  /*!
248  Returns the current line no. Mainly for error msgs / debugging,
249  but maybe usefull for other purposes.
250 
251  \see GetCurrentColumnNumber
252 
253  \return current line no.
254  */
255  virtual int GetCurrentLineNumber();
256 
257  //! Returns last error as string
258  wxString GetErrorString();
259 
260  double ParseDouble( const wxString& buffer, unsigned int& position ) ;
261  void SkipCommaSpaces( const wxString& buffer, unsigned int& position );
262  void SkipSpaces( const wxString& buffer, unsigned int& position );
263 
264 protected:
265 
266  virtual void StartElementHnd( a2dXMLTag* WXUNUSED( tag ) ) {}
267  virtual void EndElementHnd( const wxString& WXUNUSED( name ) ) {}
268  virtual void CharacterDataHnd( const wxString& WXUNUSED( text ) ) {}
269  virtual void CommentHnd( const wxString& WXUNUSED( comment ) ) {}
270  virtual void DefaultHnd( const wxString& WXUNUSED( def ) ) {}
271 
272 
273  static void BaseStartElementHnd( void* userData, const char* name, const char** atts );
274  static void BaseEndElementHnd( void* userData, const char* name );
275  static void BaseCharacterDataHnd( void* userData, const char* s, int len );
276  static void BaseCommentHnd( void* userData, const char* data );
277  static void BaseDefaultHnd( void* userData, const char* s, int len );
278 
279  //! expat parser
280  XML_Parser m_parser;
281 
282  //!buffer used for passing part of the input stream
283  char* m_buffer;
284 
285  //! true if reached end of document
286  bool m_done;
287 
288  static wxString m_encoding;
289 
290  static wxString m_version;
291 };
292 
293 //! Input and output handler for XML alike files
294 /*!
295  The file is parsed by pulling information from it.
296  One chunk of information is a XML begin_tag + attributes or an end_tag or content between
297  the tags.
298  The caller decides what should be pulled next after a reading chunk.
299  This makes it very easy to read known fixes file formats, since one can
300  directly store the information read into an object of choice.
301  This is ideal for mapping a certain XML input format to the programs
302  internal format.
303 
304  See also http://www.xmlpull.org/ for further details about XML pull parsing.
305 
306  \ingroup fileio
307 */
308 class A2DGENERALDLLEXP a2dIOHandlerXMLPull : public a2dIOHandlerXML
309 {
310 public:
311  //! Constructor.
312  /*!
313  \see a2dIOHandlerXML::a2dIOHandlerXML for description and remarks
314  */
316 
317  //! Destructor.
319 
320  //! return the tag where the stream is situated
321  a2dXMLTag* GetCurrentTag() { return m_current; }
322 
323  //! Inits the IO handler for reading
324  /*!
325  \see a2dIOHandlerXML::InitializeLoad for description and remarks
326  */
327  virtual void InitializeLoad( );
328 
329  //! Reset the object after loading
330  virtual void ResetLoad();
331 
332  //! Forces a special tag
333  /*!
334  If the current XMLeventType and the tag name is not the required type and
335  name, an a2dIOHandlerXMLException will occur.
336 
337  \see a2dIOHandlerXMLException
338 
339  \param type the required tag type
340  \param name the required tag name
341  */
342  void Require( const XMLeventType& type, wxString name );
343 
344  //! Returns name of the current XML tag
345  /*!
346  This method returns the name of the current XML tag
347 
348  \return tag name
349  */
350  wxString GetTagName();
351 
352  //! Returns the current content
353  /*!
354  Returns the content between the opening XML tag and the ending tag
355 
356  \return content between tag
357  */
358  wxString GetContent();
359 
360  //! Returns the type of current event
361  /*!
362  The event type may be one of the following:
363  - START_DOCUMENT
364  - END_DOCUMENT
365  - START_TAG
366  - END_TAG
367  - CONTENT
368 
369  \see XMLeventType
370 
371  \return the event type
372  */
373  XMLeventType GetEventType();
374 
375  //! Returns depth.
376  int GetDepth() { return m_depth; }
377 
378  //! Walks to next tag
379  /*!
380  Does internally a call to Next() and checks if the XMLEventType is an
381  <code>START_TAG</code> or <code>END_TAG</code>, otherwise an
382  a2dIOHandlerXMLException is thrown.
383 
384  \see a2dIOHandlerXMLException
385  \see Next
386 
387  \return the event type
388  */
389  XMLeventType NextTag();
390 
391  //! Walks to next element and returns event type.
392  /*!
393  Goes to the next element and returns the event type of the
394  element.
395 
396  \see NextTag
397 
398  \return the event type
399  */
400  XMLeventType Next();
401 
402 
403  //! Returns the value of an attribute
404  /*!
405  Returns the value of the attribute "attrib"
406 
407  \param attrib the attribute name
408  \param defaultv the default value (empty string by default)
409 
410  \return the value of the attribute if found or the default value
411  */
412  wxString GetAttributeValue( const wxString& attrib, const wxString& defaultv = wxT( "" ) );
413 
414  //! Forces an attribute and returns its string value.
415  /*!
416  Walks through the attributes of the current start tag and
417  returns the value of the requested attribute.
418  If the attribute is not found, an a2dIOHandlerXMLException will be
419  thrown.
420 
421  \see a2dIOHandlerXMLException
422 
423  \param attrib the attribute name
424 
425  \return the attribute value
426  */
427  wxString RequireAttributeValue( const wxString& attrib );
428 
429  //! Returns the double value of an attribute
430  /*!
431  \see GetAttributeValue
432 
433  \param attrib the attribute name
434  \param defaultv the default value (0 by default)
435 
436  \return the value of the attribute if found or the default value
437  */
438  double GetAttributeValueDouble( const wxString& attrib, double defaultv = 0 );
439 
440  //! Forces an attribute and returns its double value.
441  /*!
442  \see RequireAttributeValue
443 
444  \param attrib the attribute name
445 
446  \return the attribute value
447  */
448  double RequireAttributeValueDouble( const wxString& attrib );
449 
450  //! Returns the integer value of an attribute
451  /*!
452  \see GetAttributeValue
453 
454  \param attrib the attribute name
455  \param defaultv the default value (0 by default)
456 
457  \return the value of the attribute if found or the default value
458  */
459  int GetAttributeValueInt( const wxString& attrib, int defaultv = 0 );
460 
461  //! cast to wxUint16 of GetAttributeValueInt()
462  inline wxUint16 GetAttributeValueUint16( const wxString& attrib, wxUint16 defaultv = 0 )
463  { return ( wxUint16 ) GetAttributeValueInt( attrib, ( int ) defaultv ); }
464 
465  //! cast to wxUint32 of GetAttributeValueInt()
466  inline wxUint32 GetAttributeValueUint32( const wxString& attrib, wxUint32 defaultv = 0 )
467  { return ( wxUint32 ) GetAttributeValueLong( attrib, ( long ) defaultv ); }
468 
469  //! Forces an attribute and returns its integer value.
470  /*!
471  \see RequireAttributeValue
472 
473  \param attrib the attribute name
474 
475  \return the attribute value
476  */
477  int RequireAttributeValueInt( const wxString& attrib );
478 
479  //! Returns the long value of an attribute
480  /*!
481  \see GetAttributeValue
482 
483  \param attrib the attribute name
484  \param defaultv the default value (0 by default)
485 
486  \return the value of the attribute if found or the default value
487  */
488  long GetAttributeValueLong( const wxString& attrib, long defaultv = 0 );
489 
490  //! Forces an attribute and returns its long integer value.
491  /*!
492  \see RequireAttributeValue
493 
494  \param attrib the attribute name
495 
496  \return the attribute value
497  */
498  long RequireAttributeValueLong( const wxString& attrib );
499 
500 
501  //! Returns the boolean value of an attribute
502  /*!
503  Attribute values like "true", "true", "True"...
504  will be returned as boolean (case-insensitive).
505 
506  \remark
507  An attribute value of "1" or "0" are not valid boolean values.
508 
509  \see GetAttributeValue
510 
511  \param attrib the attribute name
512  \param defaultv the default value
513 
514  \return the value of the attribute if found or the default value
515  */
516  bool GetAttributeValueBool( const wxString& attrib, bool defaultv = false );
517 
518  //! Forces an attribute and returns its boolean value.
519  /*!
520  \see RequireAttributeValue
521 
522  \param attrib the attribute name
523 
524  \return the attribute value
525  */
526  bool RequireAttributeValueBool( const wxString& attrib );
527 
528  //! Does the current tag have this attribute?
529  bool HasAttribute( const wxString& attrib );
530 
531  //! Skips all child elements / tags of current element / tag.
532  void SkipSubTree();
533 
534  //! where in the input was column the current tag
535  virtual int GetCurrentColumnNumber();
536 
537  //! where in the input was line the current tag
538  virtual int GetCurrentLineNumber();
539 
540  //! Scale factor to scale input numbers (int double etc. ) with this.
541  //! This can be used by a derived IO handler to scale input numbers.
542  void SetScale( double scale ) { m_scale = scale; }
543 
544  //! See GetScale()
545  double GetScale() { return m_scale; }
546 
547 protected:
548 
549  virtual void StartElementHnd( a2dXMLTag* tag );
550  virtual void EndElementHnd( const wxString& name );
551  virtual void CharacterDataHnd( const wxString& text );
552  virtual void CommentHnd( const wxString& comment );
553  virtual void DefaultHnd( const wxString& def );
554 
555  //! Reads next piece of document into buffer.
556  void FillQueue();
557 
558  //! queue of begin and end elements tags not yet processed
560 
561  int m_depth;
562 
563  double m_scale;
564 
565  a2dXMLTag* m_startdoc;
566  a2dXMLTag* m_enddoc;
567 
568  //! current XML tag
570 };
571 
572 //! for writing XML files.
573 /*!
574  basic function for writing tags and attributes to a stream.
575 */
576 class A2DGENERALDLLEXP a2dIOHandlerXMLWrite : public a2dIOHandlerStrOut
577 {
578 public:
579  //! Constructor.
580  /*!
581  */
583 
584  //! Destructor.
586 
587  //! Inits the IO handler for writing
588  /*!
589  \see a2dIOHandlerXML::InitializeSave for description and remarks
590  */
591  virtual void InitializeSave( );
592 
593  //! Reset the object after saving
594  virtual void ResetSave();
595 
596  //output routines
597 
598  //! Returns depth.
599  int GetDepth() { return m_depth; }
600 
601  //! Writes a userdefined string into document.
602  /*!
603  The string might be a comment or a DTD declaration.
604 
605  \remark
606  There's no check if it's a valid XML-syntax conform string.
607  Use this method with care.
608 
609  \param string the string to write
610 
611  newLine is a line break _before_ string
612  */
613  void EndlWriteString( const wxString& string );
614 
615  //! Writes the XML header declaration.
616  /*!
617  Each XML document should begin with a XML header / prolog, which
618  informes about the XML version and the document encoding.
619 
620  \remark
621  It's highly recommended, that you write this header, otherwise you
622  might run into troubles.
623 
624  \param version the XML version (currently only "1.0" is valid)
625  \param encoding the encoding of the document
626  \param standalone <code>true</code> if it's a standalone xml doc, else <code>false</code>
627  to indicate that it has an external DTD
628 
629  */
630  void WriteStartDocument( const wxString& version, const wxString& encoding, bool standalone );
631 
632  //! Checks if all open tags are closed
633  /*!
634  This method does not write anything, but checks if there're open
635  tags with no close tag and gives an ASSERT msg.
636 
637  This method is very useful for debuging proposes and should be called.
638 
639  */
640  void WriteEndDocument();
641 
642  //! Writes start tag which has no attributes.
643  /*!
644  \remark
645  If the start tag should have attributes, you've to call
646  WriteStartElementAttributes.
647 
648  \see WriteStartElementAttributes
649 
650  \param name the tag name
651  \param newLine <code>true</code> if there should be a
652  line break _before_ the tag, else <code>false</code>
653  */
654  void WriteStartElement( const wxString& name, bool newLine = true );
655 
656  //! Writes start tag which has attributes
657  /*!
658  \remark
659  Don't forget to call WriteEndAttributes when you've written all
660  attributes.
661 
662  \see WriteEndAttributes
663 
664  \param name the tag name
665  \param newLine <code>true</code> if there should be a
666  line break _before_ the tag, else <code>false</code>
667  */
668  void WriteStartElementAttributes( const wxString& name, bool newLine = true );
669 
670  //! Writes start tag.
671  void WriteStartElement( const a2dXMLTag& tag, bool newLine = true );
672 
673  //! Writes start and end tag.
674  /*!
675  This method writes a complete set of tags
676 
677  \param name the tag name
678  \param content the content between the start an end tag
679  \param newLine <code>true</code> if there should be a
680  line break _before_ the tag, else <code>false</code>
681  */
682  void WriteElement( const wxString& name, const wxString& content = wxT( "" ), bool newLine = true );
683 
684  // ! We have to hack here because size_t is defined as 'unsigned long'
685  // and wxUint64 is defined as 'unsigned long long'.
686  template<typename w_TypeRef>
687  void WriteAttribute( const wxString& name, const w_TypeRef& value )
688  {
689  wxString error = wxT( "Wrong start tag" ) + this->m_current->m_tag;
690  wxASSERT_MSG( this->m_current->m_hasattributes , error );
691  *this << wxT( " " ) << name << wxT( "=\"" ) << value << wxT( "\"" );
692  }
693 
694  void WriteAttribute( const wxString& name, const size_t& value )
695  {
696  wxString error = wxT( "Wrong start tag" ) + this->m_current->m_tag;
697  wxASSERT_MSG( this->m_current->m_hasattributes , error );
698  *this << wxT( " " ) << name << wxT( "=\"" ) << ( wxUint32 ) value << wxT( "\"" );
699  }
700 
701  void WriteAttributeEnt( const wxString& name, const wxString& value );
702 
703  //! Writes an attribute with boolean value.
704  /*!
705  The boolean value will be written lower-case ("true" / "false")
706 
707  \see WriteStartElementAttributes
708 
709  \param name the attribute name
710  \param value the attribute value
711  \param onlyIfTrue if true the attribute is only written when value is true.
712  */
713  void WriteAttribute( const wxString& name, bool value, bool onlyIfTrue = false );
714 
715  //! Writes an a2dXMLAttribute.
716  void WriteAttribute( const a2dNamedProperty& attribute );
717 
718  //! "Closes" the start tag after writing all attributes (writes the ">" or "/>" bracket).
719  /*!
720  \param close If set to <code>true</code> a "/>" (short tag) will be written, else ">"
721  \see WriteStartElementAttributes
722  */
723  void WriteEndAttributes( bool close = false );
724 
725  //! Writes correspondending end tag for the current start tag.
726  /*!
727  \param newLine <code>true</code> if there should be a
728  line break _before_ the tag, else <code>false</code>
729  */
730  void WriteEndElement( bool newLine = true );
731 
732  //! Writes content between start and end tag.
733  /*!
734  \param content the content of the current tag
735  */
736  void WriteContent( const wxString& content );
737 
738  //! Writes a new line and takes care of indentation.
739  void WriteNewLine();
740 
741  //! number of spaces in one indentation
742  void SetIndentSize( int size ) { m_indentSize = size; }
743 
744  virtual int GetCurrentColumnNumber();
745 
746  virtual int GetCurrentLineNumber();
747 
748  void XmlEncodeStringToStream( const wxChar* string, size_t len = wxString::npos );
749 
750  //! set the format for double to be this
751  void SetFormat( const wxString& format ) { m_format = format; }
752 
753  //! write a double number.
754  virtual void WriteDouble( double d )
755  {
756  wxString str;
757  str.Printf( m_format.c_str(), d );
758  WriteString( str );
759  }
760 
761  void WriteStringEnt( const wxString& string );
762 
763  a2dIOHandlerXMLWrite& operator<<( const wxInt16& c );
764  a2dIOHandlerXMLWrite& operator<<( const wxInt32& c );
765  a2dIOHandlerXMLWrite& operator<<( const wxInt64& c );
766  a2dIOHandlerXMLWrite& operator<<( const wxUint16& c );
767  a2dIOHandlerXMLWrite& operator<<( const wxUint32& c );
768  a2dIOHandlerXMLWrite& operator<<( const wxUint64& c );
769  a2dIOHandlerXMLWrite& operator<<( const double& f );
770  a2dIOHandlerXMLWrite& operator<<( const float& f );
771 
772  a2dIOHandlerXMLWrite& operator<<( const wxChar* string );
773  a2dIOHandlerXMLWrite& operator<<( const wxString& string );
774  a2dIOHandlerXMLWrite& operator<<( char c );
775 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
776  a2dIOHandlerXMLWrite& operator<<( wchar_t wc );
777 #endif // wxUSE_UNICODE
778 
779  //! Scale factor to scale output numbers (int double etc. ) with this.
780  //! This can be used by a derived IO handler to scale output numbers.
781  void SetScale( double scale ) { m_scale = scale; }
782 
783  //! See GetScale()
784  double GetScale() { return m_scale; }
785 
786  void SetIndent( int indent ) { m_indent = indent; }
787 
788  int GetIndent() { return m_indent; }
789 
790 protected:
791 
792  wxString m_format;
793 
794  void WriteIndent();
795 
796  int m_indent;
797 
798  int m_indentSize;
799 
800  int m_depth;
801 
802  double m_scale;
803 
804  //! queue of begin and end elements tags not yet processed
806 
807  a2dXMLTag* m_startdoc;
808  a2dXMLTag* m_enddoc;
809 
810  //! current XML tag
812 };
813 
814 #if wxART2D_USE_CVGIO
815 //! Input and output handler for the XmlSer format.
816 /*!
817  \ingroup fileio
818 */
819 class A2DGENERALDLLEXP a2dIOHandlerXmlSerIn : public a2dIOHandlerXMLPull
820 {
821 public:
822  //! Constructor.
824 
825  //! Destructor.
827 
828  //! test header of the file to see if its CVG format
829  bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj, wxClassInfo* docClassInfo = NULL );
830 
831  //! load a complete document
832  /*!
833  A pointer of this class is passed to the a2dCanvasDocument,
834  which then loads itself using this parser.
835  The attribute classname in the CVG format is used to create the right
836  object while prasing the CVG and call the Load routine for that object.
837  */
838  virtual bool Load( a2dDocumentInputStream& stream , wxObject* doc );
839 
840  //! load one object from a CVG file.
841  a2dObject* LoadOneObject( wxObject* parent );
842 
843  //! set version of library or document being parsed for
844  void SetFormatVersion( wxString formatVersion ) { m_formatVersion = formatVersion; }
845 
846  //! get version of library or document
847  wxString GetFormatVersion() { return m_formatVersion; }
848 
849 protected:
850 
851  wxString m_formatVersion;
852 
853  //! the document to store/load the data found into
854  wxObject* m_doc;
855 
856 };
857 
858 //! Input and output handler for the XmlSer format.
859 /*!
860  \ingroup fileio
861 */
862 class A2DGENERALDLLEXP a2dIOHandlerXmlSerOut : public a2dIOHandlerXMLWrite
863 {
864 public:
865  //! Constructor.
867 
868  //! Destructor.
870 
871  //! this handler can also save as CVG
872  bool CanSave( const wxObject* obj = NULL ) { return true; }
873 
874  //! save a2dCanvasDocument as CVG
875  virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
876 
877 protected:
878 
879  //! the document to store/load the data found into
880  wxObject* m_doc;
881 
882 };
883 #endif //wxART2D_USE_CVGIO
884 
885 //! Input and output handler for the XmlSer format.
886 /*!
887  \ingroup fileio
888 */
889 class A2DGENERALDLLEXP a2dXmlString : public a2dIOHandlerXMLWrite
890 {
891 public:
892  //! Constructor.
893  a2dXmlString( const wxString& str = wxT( "" ) );
894 
895  //! Destructor.
896  ~a2dXmlString();
897 
898  virtual void Reset();
899 
900  //! write a command string
901  /*!
902  \param name value for name attribute of the command
903  \param close if true close the command tag, else more attributes can be added
904  */
905  void WriteCommand( const wxString& name, bool close = true );
906 
907 #if wxUSE_STD_IOSTREAM
908  const wxString& GetString() const
909  {
910  static wxString aap = wxString( m_strstream.str().c_str(), wxConvUTF8 );
911  return aap;
912  }
913 #else
914  const wxString GetString() const { return m_strstream.GetString(); }
915 #endif
916 
917  //! this handler can also save as CVG
918  bool CanSave( const wxObject* obj = NULL ) { return true; }
919 
920  //! save a2dCanvasDocument as CVG
921  virtual bool Save( a2dDocumentOutputStream& WXUNUSED( stream ), const wxObject* WXUNUSED( doc ) ) { return true; }
922 
923 protected:
924 
925  a2dDocumentStringOutputStream m_strstream;
926 };
927 
928 
929 #endif // wxART2D_USE_XMLPARSE
930 
931 #endif /* _WX_DOCVIEWXMLIO_H_ */
932 
wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
Definition: genxmlpars.h:135
For exceptions thrown while parsing XML files.
Definition: genxmlpars.h:36
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
wxString GetTypeString(const XMLeventType &type)
translate XMLeventType to a string
Definition: genxmlpars.cpp:290
wxString m_tag
tag name
Definition: genxmlpars.h:147
Input handler for the XML format.
Definition: genxmlpars.h:197
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
virtual bool Save(a2dDocumentOutputStream &stream, const wxObject *doc)
save a2dCanvasDocument as CVG
Definition: genxmlpars.h:921
wxObject * m_doc
the document to store/load the data found into
Definition: genxmlpars.h:880
Ref Counted base object.
Definition: gen.h:1045
a2dXMLTag * m_current
current XML tag
Definition: genxmlpars.h:569
a2dObject * Clone(CloneOptions options, a2dRefMap *refs=NULL) const
create an exact copy of this property
Definition: gen.cpp:1199
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
a2dSmrtPtrList< a2dXMLTag > m_elements
queue of begin and end elements tags not yet processed
Definition: genxmlpars.h:805
void SetFormat(const wxString &format)
set the format for double to be this
Definition: genxmlpars.h:751
void SetScale(double scale)
Definition: genxmlpars.h:542
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
double GetScale()
See GetScale()
Definition: genxmlpars.h:784
a2dIOHandlerXMLException(const wxString &exMessage, int exRow, int exColumn)
Constructor with row and line params.
Definition: genxmlpars.h:44
using a file stream for input, stream the file into a a2dDocument or other object ...
Definition: gen.h:3632
void SetScale(double scale)
Definition: genxmlpars.h:781
a2dXMLTag * GetCurrentTag()
return the tag where the stream is situated
Definition: genxmlpars.h:321
bool m_hasContent
flag to trigger if content was written
Definition: genxmlpars.h:160
wxStringOutputStream a2dDocumentStringOutputStream
string output stream based wxStreams
Definition: gen.h:3454
used in XML parsing to hold one tag and its atributes
Definition: genxmlpars.h:111
int GetDepth()
Returns depth.
Definition: genxmlpars.h:376
XML_Parser m_parser
expat parser
Definition: genxmlpars.h:280
std list compatible list
Definition: a2dlist.h:42
wxObject * m_doc
the document to store/load the data found into
Definition: genxmlpars.h:854
int GetDepth()
Returns depth.
Definition: genxmlpars.h:599
bool m_hasattributes
does the current XMLTag have attributes?
Definition: genxmlpars.h:163
class A2DGENERALDLLEXP a2dAttributeHash
wxString keys to hold attributes
Definition: genxmlpars.h:98
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:889
XMLeventType
Types of XML events when reading files.
Definition: genxmlpars.h:80
bool m_done
true if reached end of document
Definition: genxmlpars.h:286
virtual void DoSave(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList *towrite)
Save settings.
Definition: gen.cpp:1657
a2dSmrtPtrList< a2dXMLTag > m_elements
queue of begin and end elements tags not yet processed
Definition: genxmlpars.h:559
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
using a file stream for output, stream a a2dDocument or other wxObject into a stream.
Definition: gen.h:3751
virtual void DoLoad(wxObject *parent, a2dIOHandlerXmlSerIn &parser, a2dXmlSer_flag xmlparts)
Load settings.
Definition: gen.cpp:1699
wxUint16 GetAttributeValueUint16(const wxString &attrib, wxUint16 defaultv=0)
cast to wxUint16 of GetAttributeValueInt()
Definition: genxmlpars.h:462
a2dXMLTag * m_current
current XML tag
Definition: genxmlpars.h:811
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
general modules header files all together.
wxUint32 GetAttributeValueUint32(const wxString &attrib, wxUint32 defaultv=0)
cast to wxUint32 of GetAttributeValueInt()
Definition: genxmlpars.h:466
bool CanSave(const wxObject *obj=NULL)
this handler can also save as CVG
Definition: genxmlpars.h:872
a2dIOHandlerXMLException(const wxString &exMessage)
Constructor.
Definition: genxmlpars.h:41
char * m_buffer
buffer used for passing part of the input stream
Definition: genxmlpars.h:283
XMLeventType m_type
event type
Definition: genxmlpars.h:153
XML_Parser & GetXMLParser()
Returns the XML parser.
Definition: genxmlpars.h:233
Input and output handler for XML alike files.
Definition: genxmlpars.h:308
for writing XML files.
Definition: genxmlpars.h:576
virtual void WriteDouble(double d)
write a double number.
Definition: genxmlpars.h:754
double GetScale()
See GetScale()
Definition: genxmlpars.h:545
list of a2dObject&#39;s
Definition: gen.h:3157
A pointer class, that automatically calls SmrtPtrOwn/SmrtPtrRelease.
Definition: a2dlist.h:20
wxString m_text
Content of the tag.
Definition: genxmlpars.h:150
void SetIndentSize(int size)
number of spaces in one indentation
Definition: genxmlpars.h:742
void SetFormatVersion(wxString formatVersion)
set version of library or document being parsed for
Definition: genxmlpars.h:844
CloneOptions
options for cloning
Definition: gen.h:1200
bool CanSave(const wxObject *obj=NULL)
this handler can also save as CVG
Definition: genxmlpars.h:918
a2dIOHandlerXMLException(const a2dIOHandlerXMLException &other)
Copy constructor.
Definition: genxmlpars.h:48
wxString GetFormatVersion()
get version of library or document
Definition: genxmlpars.h:847
genxmlpars.h Source File -- Sun Oct 12 2014 17:04:20 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation