Separatista
element.h
1 /***************************************************************************
2 * Copyright (C) 2014 by Okkel Klaver *
3 * info@vanhetland.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 
21 #ifndef SEPARATISTA_ELEMENT_H
22 #define SEPARATISTA_ELEMENT_H
23 
24 #include <ctime>
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <sstream>
29 #include <Windows.h>
30 
31 #include "separatista/separatista.h"
32 #include "separatista/xerces_types.h"
33 #include "separatista/debug/debug.h"
34 #include "separatista/elementdescriptor.h"
35 #include "separatista/exception.h"
36 
37 namespace Separatista
38 {
39  // Forward decl
40  class ElementException;
41  class UnsupportedElementException;
42 
47  {
48  public:
49  virtual void elementValueChanged(Element *pElement, const wchar_t *pNewValue) = 0;
50  virtual void elementCreated(Element *pParent, Element *pChild) = 0;
51  virtual void elementDeleted(Element *pElement) = 0;
52  };
53 
54 
55  class SEPARATISTA_EXTERN Element
56  {
57  public:
63  {
65  ThrowExceptions = 0,
69  AcceptValue
70  };
71 
75  const ElementDescriptor* getElementDescriptor() const;
76 
84  virtual IOErrorCode toDOMDocument(xercesc::DOMDocument *pDOMDocument, xercesc::DOMElement *pDOMParent, const ErrorOptions errorOptions = ThrowExceptions) const = 0;
85 
90  virtual void fromDOMDocument(xercesc::DOMElement *pDOMElement, const ErrorOptions errorOptions = ThrowExceptions) = 0;
91 
97  void addElementListener(ElementListener* pElementListener);
98 
104  void removeElementListener(ElementListener* pElementListener);
105 
109  const wchar_t* getTag() const;
110 
116  virtual Element* getElementByTag(const wchar_t *pTagName, size_t nIndex = 0) const;
117 
125  virtual Element* createElementByTag(const wchar_t *pTagName, size_t nIndex = 0);
126 
131  virtual void destroyElement(Element *pChildElement);
132 
138  virtual const wchar_t* getTextValue() const;
139 
144  virtual void setValue(const wchar_t *pValue, const ErrorOptions errorOptions = ThrowExceptions);
145 
152  virtual const wchar_t* getAttributeValue(const wchar_t *pAttributeName) const;
153 
160  virtual void setAttributeValue(const wchar_t *pAttributeName, const wchar_t *pValue);
161 
166  time_t getDateValue() const;
167 
172  void setValue(const time_t Value, bool bWithTime = false, const ErrorOptions errorOptions = ThrowExceptions);
173 
177  int getIntValue() const;
178 
182  void setValue(const int Value, const ErrorOptions errorOptions = ThrowExceptions);
183 
187  double getDoubleValue() const;
188 
192  void setValue(const double d, const ErrorOptions errorOptions = ThrowExceptions);
193 
197  bool isEmpty() const;
198 
203  class TagKey
204  {
205  public:
207  TagKey(const wchar_t *pTagName, size_t nIndex, const ElementDescriptor *pBranchElementDescriptor);
208 
209  bool operator <(const TagKey &Other) const;
210 
211  bool operator ==(const TagKey &Other) const;
212 
216  static unsigned int HashKey(const wchar_t *pTagName);
217 
218  const wchar_t* getTagName() const;
219 
220  unsigned int getHash() const;
221 
222  private:
223  size_t m_nIndex;
224  const wchar_t *m_pTagName;
225  unsigned int m_nHash;
226  const ElementDescriptor *m_pBranchElementDescriptor;
227  };
228 
229  typedef std::map<const TagKey, Element*> TagKeyMap;
230 
231  typedef struct
232  {
233  TagKeyMap::const_iterator m_begin;
234  TagKeyMap::const_iterator m_end;
235  } TagKeyRange;
236 
241  virtual TagKeyRange getAllByTagName(const wchar_t *pTagName);
242 
243  protected:
248  Element(const ChildElementDescriptor* pChildElementDescriptor);
249 
253  virtual ~Element();
254 
259  Element* getParentElement() const;
260 
266  static void deleteElement(Element *pChildElement);
267 
269  void onElementValueChanged(const wchar_t *pNewValue);
270 
272  void onElementCreated(Element *pChildElement);
273 
275  void onElementDeleted();
276 
277  private:
279  const ChildElementDescriptor *m_pChildElementDescriptor;
280 
282  std::vector<ElementListener*> m_ElementListeners;
283 
285  Element *m_pParent;
286 
288  const wchar_t *m_pTag;
289  };
290 }
291 
292 #endif // ifndef SEPARATISTA_ELEMENT_H
Leave an empty value for the node.
Definition: element.h:67
Definition: elementdescriptor.h:44
Definition: element.h:203
Definition: element.h:46
Definition: elementdescriptor.h:58
ErrorOptions
Definition: element.h:62
Definition: mt940s.h:39
Definition: element.h:231
Definition: element.h:55