cfgfile 0.2.11
Loading...
Searching...
No Matches
tag_vector_of_tags.hpp
Go to the documentation of this file.
1
31#ifndef CFGFILE__TAG_VECTOR_OF_TAGS_HPP__INCLUDED
32#define CFGFILE__TAG_VECTOR_OF_TAGS_HPP__INCLUDED
33
34// cfgfile include.
35#include "tag.hpp"
36#include "exceptions.hpp"
37#include "types.hpp"
38
39// C++ include.
40#include <vector>
41#include <memory>
42
43
44namespace cfgfile {
45
46//
47// tag_vector_of_tags_t
48//
49
59template< typename T, typename Trait = string_trait_t >
61 : public tag_t< Trait >
62{
63public:
65 typedef std::shared_ptr< T > ptr_to_tag_t;
67 typedef std::vector< ptr_to_tag_t > vector_of_tags_t;
68
70 explicit tag_vector_of_tags_t( const typename Trait::string_t & name,
71 bool is_mandatory = false )
73 {
74 }
75
78 const typename Trait::string_t & name,
79 bool is_mandatory = false )
81 {
82 }
83
87
89 typename vector_of_tags_t::size_type
90 size() const
91 {
92 return m_tags.size();
93 }
94
96 const T &
97 at( typename vector_of_tags_t::size_type index ) const
98 {
99 return *m_tags.at( index );
100 }
101
103 const vector_of_tags_t &
104 values() const
105 {
106 return m_tags;
107 }
108
114 void
116 {
117 m_tags.push_back( p );
118
119 this->set_defined();
120 }
121
123 void
124 set_values( const vector_of_tags_t & v )
125 {
126 m_tags = v;
127
128 this->set_defined();
129 }
130
138 void
139 query_opt_values( vector_of_tags_t & receiver )
140 {
141 if( this->is_defined() )
142 receiver = m_tags;
143 }
144
146 const typename tag_t< Trait >::child_tags_list_t & children() const override
147 {
148 static const typename tag_t< Trait >::child_tags_list_t empty;
149
150 if( m_current )
151 return m_current->children();
152 else
153 return empty;
154 }
155
157 typename Trait::string_t print( int indent = 0 ) const override
158 {
159 typename Trait::string_t result;
160
161 if( this->is_defined() )
162 {
163 for( const ptr_to_tag_t & p : m_tags )
164 result.append( p->print( indent ) );
165 }
166
167 return result;
168 }
169
170#if defined( CFGFILE_QT_SUPPORT ) && defined( CFGFILE_XML_SUPPORT )
172 void print( QDomDocument & doc, QDomElement * parent = 0 ) const override
173 {
174 if( this->is_defined() )
175 {
176 for( const ptr_to_tag_t & p : m_tags )
177 p->print( doc, parent );
178 }
179 }
180#endif
181
183 void on_start( const parser_info_t< Trait > & info ) override
184 {
185 m_current = std::make_shared< T > ( this->name(), this->is_mandatory() );
186 m_current->set_parent( this->parent() );
187 m_current->on_start( info );
188 }
189
191 void on_finish( const parser_info_t< Trait > & info ) override
192 {
193 m_current->on_finish( info );
194 m_tags.push_back( m_current );
195 m_current.reset();
196
197 this->set_defined();
198 }
199
202 const typename Trait::string_t & str ) override
203 {
204 m_current->on_string( info, str );
205 }
206
207private:
209 vector_of_tags_t m_tags;
211 ptr_to_tag_t m_current;
212}; // class tag_vector_of_tags_t
213
214} /* namespace cfgfile */
215
216#endif // CFGFILE__TAG_VECTOR_OF_TAGS_HPP__INCLUDED
Exception in the library.
Definition exceptions.hpp:51
Base class for the tags in the configuration file.
Definition tag.hpp:58
void set_defined(bool on=true)
Set "defined" property.
Definition tag.hpp:164
bool is_mandatory() const
Definition tag.hpp:146
bool is_defined() const
Definition tag.hpp:152
const tag_t< Trait > * parent() const
Definition tag.hpp:134
const Trait::string_t & name() const
Definition tag.hpp:140
Tag with multiple instancies of the given tag.
Definition tag_vector_of_tags.hpp:62
void on_finish(const parser_info_t< Trait > &info) override
Called when tag parsing finished.
Definition tag_vector_of_tags.hpp:191
const T & at(typename vector_of_tags_t::size_type index) const
Definition tag_vector_of_tags.hpp:97
Trait::string_t print(int indent=0) const override
Print tag to the output.
Definition tag_vector_of_tags.hpp:157
std::vector< ptr_to_tag_t > vector_of_tags_t
Type of the vector of subordinate tags.
Definition tag_vector_of_tags.hpp:67
std::shared_ptr< T > ptr_to_tag_t
Type of the pointer to the subordinate tag,.
Definition tag_vector_of_tags.hpp:65
void on_string(const parser_info_t< Trait > &info, const typename Trait::string_t &str) override
Called when string found.
Definition tag_vector_of_tags.hpp:201
void print(QDomDocument &doc, QDomElement *parent=0) const override
Print tag to the output.
Definition tag_vector_of_tags.hpp:172
void set_value(ptr_to_tag_t p)
Set value.
Definition tag_vector_of_tags.hpp:115
tag_vector_of_tags_t(tag_t< Trait > &owner, const typename Trait::string_t &name, bool is_mandatory=false)
Construct tag.
Definition tag_vector_of_tags.hpp:77
const tag_t< Trait >::child_tags_list_t & children() const override
Definition tag_vector_of_tags.hpp:146
~tag_vector_of_tags_t()
Definition tag_vector_of_tags.hpp:84
void set_values(const vector_of_tags_t &v)
Set values.
Definition tag_vector_of_tags.hpp:124
void query_opt_values(vector_of_tags_t &receiver)
Query optional values.
Definition tag_vector_of_tags.hpp:139
void on_start(const parser_info_t< Trait > &info) override
Called when tag parsing started.
Definition tag_vector_of_tags.hpp:183
vector_of_tags_t::size_type size() const
Definition tag_vector_of_tags.hpp:90
tag_vector_of_tags_t(const typename Trait::string_t &name, bool is_mandatory=false)
Construct tag.
Definition tag_vector_of_tags.hpp:70
const vector_of_tags_t & values() const
Definition tag_vector_of_tags.hpp:104
Definition const.hpp:38