Separatista
elementdescriptor.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_ELEMENTDESCRIPTOR_H
22 #define SEPARATISTA_ELEMENTDESCRIPTOR_H
23 
24 #include <Windows.h>
25 
26 #include "separatista/separatista.h"
27 
28 #define SEPARATISTA_ELEMENTS(name) sizeof(name) / sizeof(ElementDescriptor), name
29 #define SEPARATISTA_TAG(tag) TEXT(tag), Separatista::HashTag(TEXT(tag))
30 
31 namespace Separatista
32 {
33  template<size_t L>
34  constexpr unsigned int HashTag(const wchar_t (&str)[L], size_t n = L - 1)
35  {
36  return n == 0 ? str[n] : HashTag(str, n - 1) + (str[n] << n);
37  }
38 
39  // Forward decl
40  class Element;
41  class Validator;
42  struct ChildElementDescriptor;
43 
45  {
49  Element* (*m_pfCreateElement)(const ChildElementDescriptor*);
51  void (*m_pfnValidate)(const wchar_t *pValue, Element *pElement);
56  };
57 
59  {
61  const wchar_t *m_pTag;
63  unsigned int m_nHash;
65  size_t m_nMin;
67  size_t m_nMax;
70  };
71 
72 }
73 
74 #endif // !defined SEPARATISTA_ELEMENTDESCRIPTOR_H
Definition: element.h:75
size_t m_nMin
Minimal presence of the element, 0 = optional.
Definition: elementdescriptor.h:65
size_t m_nElementCount
Number of child elements.
Definition: elementdescriptor.h:53
void(* m_pfnValidate)(const wchar_t *pValue, Element *pElement)
Data validation class.
Definition: elementdescriptor.h:51
const ElementDescriptor * m_pElementDescriptor
ElementDescriptor.
Definition: elementdescriptor.h:69
Definition: elementdescriptor.h:44
unsigned int m_nHash
The hash of the tag.
Definition: elementdescriptor.h:63
const wchar_t * m_pTag
The tag name of the element.
Definition: elementdescriptor.h:61
Definition: elementdescriptor.h:58
size_t m_nMax
Maximum presence of the element, 0 = infinite.
Definition: elementdescriptor.h:67
const ElementDescriptor * m_pTypeParent
Parent type ElementDescriptor, if any.
Definition: elementdescriptor.h:47
Definition: mt940s.h:39
const ChildElementDescriptor * m_pChildren
ChildElement descriptors.
Definition: elementdescriptor.h:55
Definition: element.h:55