Wolframe, 0.0.3

inputfilter.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_INPUTFILTER_INTERFACE_HPP_INCLUDED
36 #define _Wolframe_FILTER_INPUTFILTER_INTERFACE_HPP_INCLUDED
38 #include "types/docmetadata.hpp"
39 #include "filter/filterbase.hpp"
40 #include <string>
41 #include <stdexcept>
42 #include <cstring>
43 #include <cstdlib>
44 #include <boost/shared_ptr.hpp>
45 
46 namespace _Wolframe {
47 namespace langbind {
48 
52  :public ContentFilterBase
53 {
54 public:
57  enum State
58  {
60  Open,
63  };
64 
66  explicit InputFilter( const char* name_)
67  :ContentFilterBase(name_)
68  ,m_state(Start)
69  ,m_metadata( new types::DocMetaData()){}
70 
72  InputFilter( const char* name_, const types::DocMetaData& metadata)
73  :ContentFilterBase(name_)
74  ,m_state(Start)
75  ,m_metadata( new types::DocMetaData( metadata)){}
76 
81  ,m_state(o.m_state)
82  ,m_metadata( new types::DocMetaData( *o.m_metadata)){}
83 
85  virtual ~InputFilter(){}
86 
89  virtual InputFilter* copy() const=0;
90 
95  virtual void putInput( const void* ptr, std::size_t size, bool end)=0;
96 
103  virtual bool getNext( ElementType& type, const void*& element, std::size_t& elementsize)=0;
104 
107  State state() const {return m_state;}
108 
112  void setState( State s, const char* msg=0) {m_state=s; setError(msg);}
113 
117  virtual const types::DocMetaData* getMetaData()=0;
118 
120  virtual const types::DocMetaDataR& getMetaDataRef() const {return m_metadata;}
121 
123  void setAttribute( const std::string& name_, const std::string& value_)
124  {
125  m_metadata->setAttribute( name_, value_);
126  }
127 
129  void setDoctype( const std::string& doctype_)
130  {
131  m_metadata->setDoctype( doctype_);
132  }
133 
136  virtual bool checkMetaData( const types::DocMetaData&)
137  {
138  return true;
139  }
140 
141 private:
144 };
145 
149 
150 
151 }}//namespace
152 #endif
153 
154 
virtual InputFilter * copy() const =0
Get a self copy.
virtual void putInput(const void *ptr, std::size_t size, bool end)=0
Declare the next input chunk to the filter.
InputFilter(const char *name_, const types::DocMetaData &metadata)
Constructor.
Definition: inputfilter.hpp:72
Document meta data representation.
Definition: docmetadata.hpp:46
InputFilter(const InputFilter &o)
Copy constructor.
Definition: inputfilter.hpp:79
Base of a content input/ouput filter.
Definition: filterbase.hpp:140
State
State of the input filter.
Definition: inputfilter.hpp:57
virtual bool getNext(ElementType &type, const void *&element, std::size_t &elementsize)=0
Get next element.
InputFilter(const char *name_)
Constructor.
Definition: inputfilter.hpp:66
Structure representing document meta data.
void setAttribute(const std::string &name_, const std::string &value_)
Set a document meta data attribute.
Definition: inputfilter.hpp:123
Shared reference to an object exchangeable in a single thread context.
void setDoctype(const std::string &doctype_)
Set a document type.
Definition: inputfilter.hpp:129
void setState(State s, const char *msg=0)
Set input filter state with error message.
Definition: inputfilter.hpp:112
virtual ~InputFilter()
Destructor.
Definition: inputfilter.hpp:85
have to stop processing with an error
Definition: inputfilter.hpp:62
virtual bool checkMetaData(const types::DocMetaData &)
Validate the meta data passed to be correct for this filter.
Definition: inputfilter.hpp:136
ElementType
Content element type that describes the role of the element in the structured input.
Definition: filterbase.hpp:66
Input filter.
Definition: inputfilter.hpp:51
void setError(const char *msg=0)
Set input filter error message.
Definition: filterbase.hpp:91
have to yield processing because end of message reached
Definition: inputfilter.hpp:61
types::SharedReference< InputFilter > InputFilterR
Shared input filter (langbind::InputFilter) reference.
Definition: inputfilter.hpp:148
State state() const
Get the current state.
Definition: inputfilter.hpp:107
serving data - normal input processing
Definition: inputfilter.hpp:60
boost::shared_ptr< DocMetaData > DocMetaDataR
Shared meta data reference.
Definition: docmetadata.hpp:143
State m_state
state
Definition: inputfilter.hpp:142
types::DocMetaDataR m_metadata
meta data reference
Definition: inputfilter.hpp:143
Common definitions of input and output filter.
virtual const types::DocMetaDataR & getMetaDataRef() const
Get a shared reference to the document meta data to link output filter to input filer meta data...
Definition: inputfilter.hpp:120
state after first initialization
Definition: inputfilter.hpp:59
virtual const types::DocMetaData * getMetaData()=0
Get the document meta data if available.