Wolframe, 0.0.3

filterbase.hpp
Go to the documentation of this file.
1 /************************************************************************
2 Copyright (C) 2011 - 2014 Project Wolframe.
3 All rights reserved.
4 
5 This file is part of Project Wolframe.
6 
7 Commercial Usage
8 Licensees holding valid Project Wolframe Commercial licenses may
9 use this file in accordance with the Project Wolframe
10 Commercial License Agreement provided with the Software or,
11 alternatively, in accordance with the terms contained
12 in a written agreement between the licensee and Project Wolframe.
13 
14 GNU General Public License Usage
15 Alternatively, you can redistribute this file and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19 
20 Wolframe is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
27 
28 If you have questions regarding the use of this file, please contact
29 Project Wolframe.
30 
31 ************************************************************************/
34 
35 #ifndef _Wolframe_FILTER_FILTERBASE_HPP_INCLUDED
36 #define _Wolframe_FILTER_FILTERBASE_HPP_INCLUDED
37 #include <string>
38 #include <cstring>
39 
40 namespace _Wolframe {
41 namespace langbind {
42 
46 {
47 public:
48  explicit FilterBase( const char* name_)
49  :m_flags(None)
50  ,m_name(name_)
51  {
52  m_errorbuf[0] = '\0';
53  }
54 
56  :m_flags(o.m_flags)
57  ,m_name(o.m_name)
58  {
59  setError( o.m_errorbuf);
60  }
61 
62  virtual ~FilterBase(){}
63 
67  {
72  };
76  static const char* elementTypeName( ElementType i)
77  {
78  static const char* ar[] = {"OpenTag","Attribute","Value","CloseTag"};
79  return ar[(int)i];
80  }
81 
84  virtual const char* getError() const
85  {
86  return m_errorbuf[0]?m_errorbuf:0;
87  }
88 
91  void setError( const char* msg=0)
92  {
93  if (msg)
94  {
95  std::size_t msglen = std::strlen( msg);
96  if (msglen >= ErrorBufSize) msglen = (std::size_t)ErrorBufSize-1;
97  std::memcpy( m_errorbuf, msg, msglen);
98  m_errorbuf[ msglen] = 0;
99  }
100  else
101  {
102  m_errorbuf[ 0] = 0;
103  }
104  }
105 
106  enum Flags
107  {
108  None=0x00,
112  };
113 
116  bool flag( Flags f) const {return ((int)f & (int)m_flags) == (int)f;}
117 
120  Flags flags() const {return m_flags;}
121 
124  virtual bool setFlags( Flags f) {int ff=(int)m_flags | (int)f; m_flags=(Flags)ff; return true;}
126  virtual bool checkSetFlags( Flags) const {return true;}
127 
129  const char* name() const {return m_name;}
130 
131 private:
132  enum {ErrorBufSize=128};
135  const char* m_name;
136 };
137 
141  :public FilterBase
142 {
143 public:
144  ContentFilterBase( const char* name_)
145  :FilterBase( name_){}
147  :FilterBase( o){}
148 
153  virtual bool getValue( const char* /*name*/, std::string& /*val*/) const
154  {
155  return false;
156  }
157 
162  virtual bool setValue( const char* /*name*/, const std::string& /*val*/)
163  {
164  return false;
165  }
166 };
167 
168 }}//namespace
169 #endif
attribute name
Definition: filterbase.hpp:69
Definition: filterbase.hpp:132
const char * m_name
name of the filter
Definition: filterbase.hpp:135
Flags flags() const
Get all flags.
Definition: filterbase.hpp:120
FilterBase(const char *name_)
Definition: filterbase.hpp:48
Base of a content input/ouput filter.
Definition: filterbase.hpp:140
do serialization with array index elements, if implemented
Definition: filterbase.hpp:109
Base of input/ouput filter.
Definition: filterbase.hpp:45
virtual bool getValue(const char *, std::string &) const
Get a member value of the filter. Throws on conversion error.
Definition: filterbase.hpp:153
open new hierarchy level
Definition: filterbase.hpp:68
Flags
Definition: filterbase.hpp:106
virtual bool setValue(const char *, const std::string &)
Set a member value of the filter. Throws on conversion error.
Definition: filterbase.hpp:162
ContentFilterBase(const ContentFilterBase &o)
Definition: filterbase.hpp:146
virtual const char * getError() const
Get the las error in case of error state.
Definition: filterbase.hpp:84
true, if the result is propagated to be case insensitive
Definition: filterbase.hpp:110
const char * name() const
Get the name of the filter.
Definition: filterbase.hpp:129
no flags set
Definition: filterbase.hpp:108
virtual bool setFlags(Flags f)
Set a flag (or a set of flags)
Definition: filterbase.hpp:124
ElementType
Content element type that describes the role of the element in the structured input.
Definition: filterbase.hpp:66
void setError(const char *msg=0)
Set input filter error message.
Definition: filterbase.hpp:91
true, if the result is propagated to have no attribute support (only open/close tag and value) ...
Definition: filterbase.hpp:111
static const char * elementTypeName(ElementType i)
Get the name of an ElementType as string.
Definition: filterbase.hpp:76
char m_errorbuf[ErrorBufSize]
error string
Definition: filterbase.hpp:133
virtual ~FilterBase()
Definition: filterbase.hpp:62
virtual bool checkSetFlags(Flags) const
Test if a flag can be set (allowed)
Definition: filterbase.hpp:126
bool flag(Flags f) const
Query a flag (or a set of flags)
Definition: filterbase.hpp:116
close current hierarchy level
Definition: filterbase.hpp:71
ContentFilterBase(const char *name_)
Definition: filterbase.hpp:144
FilterBase(const FilterBase &o)
Definition: filterbase.hpp:55
content or attribute value
Definition: filterbase.hpp:70
Flags m_flags
flags
Definition: filterbase.hpp:134