1 /***************************************************************************
2                ulxr_valueparse_wb.h  -  parse wbxml-rpc primitive values
3                              -------------------
4     begin                : Fri Jan 09 2004
5     copyright            : (C) 2002-2007 by Ewald Arnold
6     email                : ulxmlrpcpp@ewald-arnold.de
7 
8     $Id: ulxr_valueparse_wb.h 1154 2009-08-16 09:24:53Z ewald-arnold $
9 
10  ***************************************************************************/
11 
12 /**************************************************************************
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License as
16  * published by the Free Software Foundation; either version 2 of the License,
17  * or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  ***************************************************************************/
29 
30 #ifndef ULXR_VALUEPARSE_WB_H
31 #define ULXR_VALUEPARSE_WB_H
32 
33 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
34 
35 #include <ulxmlrpcpp/ulxr_wbxmlparse.h>
36 #include <ulxmlrpcpp/ulxr_valueparse_base.h>
37 
38 #include <stack>
39 
40 
41 namespace ulxr {
42 
43 
44 /** Base class for WBXML RPC parsing.
45   *
46   * IMPORTANT:
47   * The current "Value" is moved around via pointers and is not
48   * automatically destroyed. The object taking over the "Value" resp. the object
49   * storing the value somehow else must "delete" the "Value" it gets.
50   *
51   * @see ArrayState::takeValue
52   * @ingroup grp_ulxr_parser
53   */
54 class ULXR_API_DECL0 ValueParserWb : public ValueParserBase,
55                                   public WbXmlParser
56 {
57  public:
58 
59  /** Constructs a parser.
60    */
61    ValueParserWb();
62 
63  /** Destroys the parser.
64    */
65    virtual ~ValueParserWb();
66 
67    enum ValueWellKnownToken
68    {
69      //* @attention Never ever change these values or their order
70      wbToken_Value     = wbxml_TAG_C_FIRST,   // 0x45
71      wbToken_Array,                           // 0x46
72      wbToken_Data,                            // 0x47
73      wbToken_Struct,                          // 0x48
74      wbToken_Member,                          // 0x49
75      wbToken_Name,                            // 0x4a
76      wbToken_Boolean,                         // 0x4b
77      wbToken_Int,                             // 0x4c
78      wbToken_I4,                              // 0x4d
79      wbToken_Double,                          // 0x4e
80      wbToken_String,                          // 0x4f
81      wbToken_Base64,                          // 0x50
82      wbToken_Date,                            // 0x51
83      wbToken_ValueParserLast                  // 0x52
84    };
85 
86  protected:
87 
88  /** Tests if the current opening tag is to be parsed by this
89    * inheritance level or by the parent.
90    * @param  token  current well known token
91    * @param  attr   tag attributes
92    * @return true: element has been handled
93    */
94    bool testStartElement(unsigned token, const Attributes &attr);
95 
96  /** C++ callback for an opening XML tag.
97    * @param  token  current well known token
98    * @param  attr   tag attributes
99    */
100    virtual void startElement(unsigned token, const Attributes &attr);
101 
102  /** C++ callback for a closing XML tag.
103    * @return true: element has been handled
104    */
105    bool testEndElement();
106 
107  /** C++ callback for a closing XML tag.
108    */
109    virtual void endElement();
110 
111 /** Helper class to represent the data of the current parsing step
112   * when the xml element is an Integer
113   */
114   class ULXR_API_DECL0 IntegerState : public ValueParserBase::ValueState
115   {
116    public:
117 
118    /** Constructs a IntegerState.
119      * @param  st   the actual state
120      */
121      IntegerState(unsigned st);
122 
123    /** Transfers a Value into the ValueState.
124      * @param  val   the value
125      * @param  candel: @li true:  value is unique here, delete at end
126      *                 @li false: value is shared here, delete it somewhere else
127      */
128      virtual void takeValue(Value *val, bool candel = true);
129 
130    private:
131      IntegerState(const IntegerState&); // forbid this
132      IntegerState& operator= (const IntegerState&);
133   };
134 
135   friend class IntegerState;
136 
137  /** Gets a pointer to the topmost ValueState.
138    * @return pointer to ValueState
139    */
140    ValueState *getTopValueState() const;
141 };
142 
143 
144 }  // namespace ulxr
145 
146 
147 #endif // ULXR_VALUEPARSE_WB_H
148