1 #include <cls_3/tags/h/tag.hpp>
2
3 namespace cls_3
4 {
5
6 namespace tags
7 {
8
9 ///
10 /// tag_t
11 ///
12
tag_t(const std::string & name)13 tag_t::tag_t( const std::string &name )
14 : m_name( name )
15 {
16 }
17
tag_t(tag_t & owner,const std::string & name)18 tag_t::tag_t(
19 tag_t &owner,
20 const std::string &name
21 )
22 : m_name( name )
23 {
24 owner.tag_add( self_tag() );
25 }
26
~tag_t()27 tag_t::~tag_t()
28 {
29 }
30
31 tag_t &
self_tag()32 tag_t::self_tag()
33 {
34 return *this;
35 }
36
37 const tag_t &
self_tag() const38 tag_t::self_tag() const
39 {
40 return *this;
41 }
42
43 void
on_start(const parser_context_info_t &)44 tag_t::on_start( const parser_context_info_t &/*parser_context_info*/ )
45 {
46 }
47
48 void
on_finish(const parser_context_info_t &)49 tag_t::on_finish( const parser_context_info_t &/*parser_context_info*/ )
50 {
51 // Checks all mandatory children tags
52
53 for( size_t i = 0; i < query_child_tags().size(); i++ )
54 {
55 if( ( query_child_tags()[i]->is_mandatory() )
56 && ( !( query_child_tags()[i]->is_defined() ) )
57 )
58 {
59 throw undefined_mandatory_tag_ex_t(
60 query_child_tags()[i]->query_name() );
61 }
62 }
63 }
64
65 void
on_tag(const parser_context_info_t &,tag_t &)66 tag_t::on_tag(
67 const parser_context_info_t &/*parser_context_info*/,
68 tag_t & /*tag*/ )
69 {
70 }
71
72 const std::vector< tag_t * > &
query_child_tags()73 tag_t::query_child_tags()
74 {
75 return m_children_tags;
76 }
77
78 const std::string &
query_name() const79 tag_t::query_name() const
80 {
81 return m_name;
82 }
83
84 bool
compare_name(const std::string & name) const85 tag_t::compare_name( const std::string &name ) const
86 {
87 return 0 == m_name.compare( name );
88 }
89
90 bool
is_mandatory() const91 tag_t::is_mandatory() const
92 {
93 return false;
94 }
95
96 bool
is_defined() const97 tag_t::is_defined() const
98 {
99 return false;
100 }
101
102 void
reset()103 tag_t::reset()
104 {
105 // Reset all children tags
106 for( size_t i = 0; i < query_child_tags().size(); i++ )
107 {
108 query_child_tags().at( i )->reset();
109 }
110 }
111
112 void
on_tok_space(const parser_context_info_t &,const std::string &)113 tag_t::on_tok_space(
114 const parser_context_info_t &/*parser_context_info*/,
115 const std::string & /*tok_value*/ )
116 {
117 }
118
119 void
on_tok_nonspace(const parser_context_info_t &,const std::string &)120 tag_t::on_tok_nonspace(
121 const parser_context_info_t & /*parser_context_info*/,
122 const std::string & /*tok_value*/ )
123 {
124 }
125
126 void
on_tok_string(const parser_context_info_t &,const std::string &)127 tag_t::on_tok_string(
128 const parser_context_info_t & /*parser_context_info*/,
129 const std::string & /*tok_value*/ )
130 {
131 }
132
133 void
on_tok_comment(const parser_context_info_t &,const std::string &,const std::string &,const std::string &)134 tag_t::on_tok_comment(
135 const parser_context_info_t & /*parser_context_info*/,
136 const std::string & /*start_marker*/,
137 const std::string & /*tok_contents*/,
138 const std::string & /*end_marker*/ )
139 {
140 }
141
142 void
on_tok_verbatim_string(const parser_context_info_t &,const std::string &,const std::string &,const std::string &)143 tag_t::on_tok_verbatim_string(
144 const parser_context_info_t & /*parser_context_info*/,
145 const std::string & /*start_marker*/,
146 const std::string & /*tok_contents*/,
147 const std::string & /*end_marker*/ )
148 {
149 }
150
151
152 void
format(tag_formatter_t & fmt)153 tag_t::format( tag_formatter_t & fmt )
154 {
155 if( is_defined() )
156 {
157 fmt.start_tag( query_name() );
158
159 on_format( fmt );
160
161 // ������� ��� �������� ����
162 for( size_t i = 0; i < query_child_tags().size(); i++ )
163 {
164 query_child_tags().at( i )->format( fmt );
165 }
166
167 fmt.finish_tag();
168 }
169 }
170
171 void
tag_add(tag_t & tag)172 tag_t::tag_add( tag_t & tag )
173 {
174 m_children_tags.push_back( &tag );
175 }
176
177 void
tag_remove(tag_t & tag)178 tag_t::tag_remove( tag_t & tag )
179 {
180 std::vector< tag_t * >::iterator to_delete;
181
182 if( ( to_delete = find(
183 m_children_tags.begin(),
184 m_children_tags.end(),
185 &tag )
186 ) != m_children_tags.end()
187 )
188 {
189 m_children_tags.erase( to_delete );
190 }
191 }
192
193 tag_t &
get_child_by_name(const std::string & tag_name)194 tag_t::get_child_by_name( const std::string &tag_name )
195 {
196 for( size_t i = 0; i < m_children_tags.size(); i++ )
197 {
198 if( m_children_tags[ i ]->compare_name( tag_name ) )
199 {
200 return *( m_children_tags[ i ] );
201 }
202 }
203
204 // ��� �� ������ � ���������� ����������� �����:
205
206 // ������� ����������
207 throw children_tag_not_found_ex_t( tag_name );
208 }
209
210 void
on_format(tag_formatter_t &)211 tag_t::on_format( tag_formatter_t & /*fmt*/ )
212 {
213 }
214
215 } // namespace tags
216
217 } // namespace cls_3
218