Wolframe, 0.0.3

ptreefilter.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _Wolframe_FILTER_PTREE_FILTER_HPP_INCLUDED
37 #define _Wolframe_FILTER_PTREE_FILTER_HPP_INCLUDED
38 #include "filter/typedfilter.hpp"
39 #include "types/propertyTree.hpp"
40 #include <vector>
41 #include <string>
42 
43 namespace _Wolframe {
44 namespace langbind {
45 
49 {
50 public:
53  :TypedInputFilter("ptree")
54  ,m_state(0)
55  {
56  State st;
57  st.itr = pt.begin();
58  st.end = pt.end();
59  m_stk.push_back(st);
60  }
61 
66  ,m_stk(o.m_stk)
67  ,m_state(o.m_state){}
68 
71 
74  virtual TypedInputFilter* copy() const {return new PropertyTreeInputFilter(*this);}
75 
77  virtual bool getNext( ElementType& type, types::VariantConst& element);
78 
80  virtual bool setFlags( Flags f);
81 
83  virtual bool checkSetFlags( Flags f) const;
84 
85  std::string posLogText() const
86  {
87  return m_position.logtext();
88  }
89 
90 private:
93  struct State
94  {
97  };
98 
99 private:
100  std::vector<State> m_stk; //< stack of iterator states
101  int m_state; //< fetching state of current element
102  types::PropertyTree::Position m_position; //< position of current element
103 };
104 
108 {
109 public:
112 
115 
118  virtual TypedOutputFilter* copy() const {return new PropertyTreeOutputFilter(*this);}
119 
121  virtual bool print( ElementType type, const types::VariantConst& element);
122 
124  const types::PropertyTree::Node& content() const {return m_stk.back().m_node;}
125 
126 private:
129  struct State
130  {
131  State(){}
132  State( const std::string& name_)
133  :m_name(name_){}
134  State( const State& o)
135  :m_name(o.m_name), m_node(o.m_node){}
136 
137  std::string m_name;
139  };
140  std::vector<State> m_stk; //< build property tree stack
141  std::string m_attribute; //< parsed attribute name
142 };
143 
144 }}//namespace
145 #endif
146 
147 
148 
std::vector< State > m_stk
Definition: ptreefilter.hpp:140
std::string m_attribute
Definition: ptreefilter.hpp:141
Property tree node.
Definition: propertyTree.hpp:86
virtual bool checkSetFlags(Flags f) const
Implements FilterBase::checkSetFlags()const.
std::string m_name
Definition: ptreefilter.hpp:137
types::PropertyTree::Node::const_iterator itr
Definition: ptreefilter.hpp:95
types::PropertyTree::Position m_position
Definition: ptreefilter.hpp:102
PropertyTreeInputFilter(const PropertyTreeInputFilter &o)
Copy constructor.
Definition: ptreefilter.hpp:64
PropertyTreeInputFilter(const types::PropertyTree::Node &pt)
Constructor.
Definition: ptreefilter.hpp:52
State of property tree input filter.
Definition: ptreefilter.hpp:93
Flags
Definition: filterbase.hpp:106
std::string logtext() const
virtual ~PropertyTreeInputFilter()
Destructor.
Definition: ptreefilter.hpp:70
virtual TypedInputFilter * copy() const
Get a self copy.
Definition: ptreefilter.hpp:74
State(const std::string &name_)
Definition: ptreefilter.hpp:132
Variant value type that represents a variant copy without content ownership.
Definition: variant.hpp:286
virtual TypedOutputFilter * copy() const
Get a self copy.
Definition: ptreefilter.hpp:118
std::vector< Assignment >::const_iterator end() const
Definition: propertyTree.hpp:149
const types::PropertyTree::Node & content() const
Get the content.
Definition: ptreefilter.hpp:124
virtual bool getNext(ElementType &type, types::VariantConst &element)
Implementation of TypedInputFilter::getNext(ElementType&,types::VariantConst&)
std::vector< Assignment >::const_iterator begin() const
Definition: propertyTree.hpp:148
types::PropertyTree::Node m_node
Definition: ptreefilter.hpp:138
ElementType
Content element type that describes the role of the element in the structured input.
Definition: filterbase.hpp:66
Filter for property tree structures.
Definition: ptreefilter.hpp:48
Source line info with filename reference for error messages.
Definition: fileLineInfo.hpp:47
std::vector< State > m_stk
Definition: ptreefilter.hpp:100
std::string posLogText() const
Definition: ptreefilter.hpp:85
virtual ~PropertyTreeOutputFilter()
Destructor.
Definition: ptreefilter.hpp:114
std::vector< Assignment >::const_iterator const_iterator
Definition: propertyTree.hpp:145
Output filter with atomic values having a type.
Definition: typedfilter.hpp:104
State(const State &o)
Definition: ptreefilter.hpp:134
Interface to a key value tree based on boost::property_tree::ptree with position info for better erro...
virtual bool setFlags(Flags f)
Implements FilterBase::setFlags()
int m_state
Definition: ptreefilter.hpp:101
State of property tree output filter.
Definition: ptreefilter.hpp:129
virtual bool print(ElementType type, const types::VariantConst &element)
Implementation of TypedOutputFilter::print(ElementType,const types::VariantConst&) ...
Output filter for serializing a structure as property tree.
Definition: ptreefilter.hpp:107
Typed interface for input/output filter.
types::PropertyTree::Node::const_iterator end
Definition: ptreefilter.hpp:96
Input filter with atomic values having a type.
Definition: typedfilter.hpp:48