Wolframe, 0.0.3

outputfilter.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_OUTPUTFILTER_INTERFACE_HPP_INCLUDED
36 #define _Wolframe_FILTER_OUTPUTFILTER_INTERFACE_HPP_INCLUDED
38 #include "types/docmetadata.hpp"
39 #include "filter/filterbase.hpp"
40 #include <string>
41 #include <cstring>
42 #include <stdexcept>
43 
44 namespace _Wolframe {
45 namespace langbind {
46 
50  :public ContentFilterBase
51 {
52 public:
55  enum State
56  {
58  Open,
61  };
62 
64  OutputFilter( const char* name_, const types::DocMetaDataR& inheritMetadata_)
65  :ContentFilterBase(name_)
66  ,m_state(Start)
68  ,m_inheritMetadata(inheritMetadata_)
69  {}
70 
72  explicit OutputFilter( const char* name_)
73  :ContentFilterBase(name_)
74  ,m_state(Start)
76  {}
77 
82  ,m_state(o.m_state)
86  {}
87 
89  virtual ~OutputFilter(){}
90 
93  virtual OutputFilter* copy() const=0;
94 
100  virtual bool print( ElementType type, const void* element, std::size_t elementsize)=0;
101 
106  bool print( ElementType type, const std::string& element)
107  {
108  return print( type, element.c_str(), element.size());
109  }
110 
114  virtual void getOutput( const void*& buf, std::size_t& bufsize)=0;
115 
117  virtual bool close()=0;
118 
123  {
124  if (state() != Start)
125  {
126  throw std::runtime_error( "cannot set output meta data anymore after first call of print");
127  }
128  m_metadata = md;
129  }
130 
133  {
135  rt.join( m_metadata.attributes());
136  return rt;
137  }
138 
141  virtual void inheritMetaData( const types::DocMetaDataR mdr)
142  {
143  m_inheritMetadata = mdr;
144  }
145 
148  State state() const {return m_state;}
149 
153  void setState( State s, const char* msg=0) {m_state=s; setError(msg);}
154 
158  void setAttribute( const std::string& name_, const std::string& value_)
159  {
160  if (state() != Start)
161  {
162  throw std::runtime_error( "cannot set output meta data anymore after first call of print");
163  }
164  m_metadata.setAttribute( name_, value_);
165  }
166 
169  void setDoctype( const std::string& id_)
170  {
171  if (state() != Start)
172  {
173  throw std::runtime_error( "cannot set document type anymore after first call of print");
174  }
175  m_metadata.setDoctype( id_);
176  }
177 
178  void setOutputChunkSize( unsigned int outputChunkSize_)
179  {
180  m_outputChunkSize = outputChunkSize_;
181  }
182 
183  unsigned int outputChunkSize() const
184  {
185  return m_outputChunkSize;
186  }
187 
188 private:
190  unsigned int m_outputChunkSize;
193 };
194 
198 
199 }}//namespace
200 #endif
201 
202 
virtual bool print(ElementType type, const void *element, std::size_t elementsize)=0
Print the follow element to the buffer.
virtual bool close()=0
Print the final close tag, if not printed yet, to close the output.
serving data - normal input processing
Definition: outputfilter.hpp:58
Document meta data representation.
Definition: docmetadata.hpp:46
types::DocMetaDataR m_inheritMetadata
reference to meta data inherited from input
Definition: outputfilter.hpp:191
have to stop processing with an error
Definition: outputfilter.hpp:60
Base of a content input/ouput filter.
Definition: filterbase.hpp:140
virtual void getOutput(const void *&buf, std::size_t &bufsize)=0
Get the last output chunk.
State
State of the input filter used in the application processor iterating loop to decide what to do...
Definition: outputfilter.hpp:55
Structure representing document meta data.
virtual void inheritMetaData(const types::DocMetaDataR mdr)
Declare the inherited document meta data.
Definition: outputfilter.hpp:141
Shared reference to an object exchangeable in a single thread context.
void setAttribute(const std::string &name_, const std::string &value_)
Set one document meta data element.
Definition: outputfilter.hpp:158
void setState(State s, const char *msg=0)
Set output filter state with error message.
Definition: outputfilter.hpp:153
virtual ~OutputFilter()
Destructor.
Definition: outputfilter.hpp:89
types::DocMetaData m_metadata
document meta data
Definition: outputfilter.hpp:192
virtual OutputFilter * copy() const =0
Get a self copy.
OutputFilter(const OutputFilter &o)
Copy constructor.
Definition: outputfilter.hpp:80
state after first initialization
Definition: outputfilter.hpp:57
void setAttribute(const Attribute &attr)
Set a unique attribute by name (add or redefine)
State state() const
Get the current state.
Definition: outputfilter.hpp:148
void setMetaData(const types::DocMetaData &md)
Initialize the document meta data.
Definition: outputfilter.hpp:122
types::DocMetaData getMetaData() const
Get the document meta data.
Definition: outputfilter.hpp:132
void join(const std::vector< Attribute > &attributes_)
Update or insert all attributes passed.
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
const std::string & doctype() const
Get the document type.
Definition: docmetadata.hpp:113
Output filter.
Definition: outputfilter.hpp:49
OutputFilter(const char *name_, const types::DocMetaDataR &inheritMetadata_)
Constructor.
Definition: outputfilter.hpp:64
State m_state
state
Definition: outputfilter.hpp:189
void setDoctype(const std::string &doctype_)
Set the document type.
Definition: docmetadata.hpp:83
void setDoctype(const std::string &id_)
Set the document type meta data element.
Definition: outputfilter.hpp:169
bool print(ElementType type, const std::string &element)
Print the follow element to the buffer.
Definition: outputfilter.hpp:106
const std::vector< Attribute > & attributes() const
Get the meta data attributes.
Definition: docmetadata.hpp:119
types::SharedReference< OutputFilter > OutputFilterR
Shared output filter (langbind::OutputFilter) reference.
Definition: outputfilter.hpp:197
boost::shared_ptr< DocMetaData > DocMetaDataR
Shared meta data reference.
Definition: docmetadata.hpp:143
OutputFilter(const char *name_)
Constructor.
Definition: outputfilter.hpp:72
unsigned int m_outputChunkSize
output chunk size
Definition: outputfilter.hpp:190
Common definitions of input and output filter.
unsigned int outputChunkSize() const
Definition: outputfilter.hpp:183
void setOutputChunkSize(unsigned int outputChunkSize_)
Definition: outputfilter.hpp:178
have to yield processing because end of message reached
Definition: outputfilter.hpp:59