coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
directive.h
Go to the documentation of this file.
1 #ifndef DIRECTIVE_H
2 #define DIRECTIVE_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 
40 #include "line_despatch.h"
41 #include "chew.h"
42 #include <map>
43 #include <vector>
44 
54 struct directive_base : private no_copy
55 {
65  static line_type eval(std::string keyword, chewer<parse_buffer> & chew) {
66  return eval(get_type(keyword),chew);
67  }
68 
70  static void erase_all();
71 
72 protected:
73 
78  static void report(std::string const & keyword, std::string const & arg);
79 
88  static void report(bool seen,
89  std::string const & keyword, std::string const & arg);
90 
100 
109  static line_type
111 
112 private:
113 
117  static directive_type get_type(std::string const & keyword);
119  static std::map<std::string, directive_type> _keyword_to_type_map_;
123  static std::vector<evaluator> _evaluator_tab_;
124 };
125 
140 template<directive_type Type>
142 {
143 
144  friend struct directive_base;
146  static directive_type const _type_ = Type;
147 
149  virtual ~directive() = default;
150 
154  explicit directive(std::string const & arg)
155  : _loc(insert(arg)) {}
156 
158  std::string const & argument() const {
159  return _loc->first;
160  }
161 
163  virtual void report() {
164  directive_base::report(_loc->second,_keyword_,_loc->first);
165  _loc->second = true;
166 
167  }
168 
170  bool reported() const {
171  return _loc->second;
172  }
173 
175  void set_reported(bool reported = true) {
176  _loc->second = reported;
177  }
178 
179 protected:
180 
189  static line_type eval(chewer<parse_buffer> & chew);
190 
196  using directives_table = std::map<std::string,bool> ;
198  using table_entry = directives_table::value_type;
199 
205  static directives_table::iterator insert(std::string const & arg) {
206  return _directives_tab_.insert(table_entry(arg,false)).first;
207  }
208 
210  directives_table::iterator _loc;
211 
213  static std::string const _keyword_;
216 };
217 
219 
220 template<>
222 
223 template<>
225 
226 template<>
228 
229 template<>
231 
232 template<>
234 
235 template<>
237 
238 template<>
240 
241 template<>
243 
244 template<>
246 
247 template<>
249 
250 template<>
252 
253 template<>
255 
256 template<>
258 
259 
261 
262 #endif /* EOF*/
directive(std::string const &arg)
Explicitly construct a directive from a directive body.
Definition: directive.h:154
directives_table::iterator _loc
An iterator locating this directive in the global lookup table.
Definition: directive.h:210
static void report(std::string const &keyword, std::string const &arg)
Report a directive.
static std::map< std::string, directive_type > _keyword_to_type_map_
Map from keywords to directive types.
Definition: directive.h:119
line_type(*)(chewer< parse_buffer > &) evaluator
Type of evaluation functions applied to directive bodies.
Definition: directive.h:115
Encapsulates a directive of a given type.
Definition: directive.h:141
bool reported() const
Say whether the directive has been reported.
Definition: directive.h:170
static line_type eval_ifdef_or_ifndef(directive_type type, chewer< parse_buffer > &chew)
Evaluate an #ifdef or #ifndef directive.
virtual ~directive()=default
Destructor.
static directives_table::iterator insert(std::string const &arg)
Insert a directive into the global lookup table.
Definition: directive.h:205
static std::string const _keyword_
The keyword for directives of the type.
Definition: directive.h:213
static line_type eval(std::string keyword, chewer< parse_buffer > &chew)
Evaluate a directive.
Definition: directive.h:65
void set_reported(bool reported=true)
Set the status of the directive as reported or unreported.
Definition: directive.h:175
static directive_type const _type_
The directive_type of this class.
Definition: directive.h:146
virtual void report()
Report the directive.
Definition: directive.h:163
static line_type eval(chewer< parse_buffer > &chew)
Evaluate a directive of this type.
A utility class to prevent copying of containing class.
Definition: prohibit.h:68
directive_type
Symbolic constants denoting types of directives.
static directive_type get_type(std::string const &keyword)
Get the directive_type of a directive given a keyword.
static directives_table _directives_tab_
The global lookup table for directives of this type.
Definition: directive.h:215
template struct directive_base is a base for specializations of template struct directive<Type> ...
Definition: directive.h:54
directives_table::value_type table_entry
Type of entry in directives_table.
Definition: directive.h:198
std::map< std::string, bool > directives_table
Type of global lookup table for directives of this type.
Definition: directive.h:196
static std::vector< evaluator > _evaluator_tab_
Table of evaluation functions for directive types, indexed by directive_type.
Definition: directive.h:123
`template struct chewer<CharSeq> is a cursor-like type that is associated with a character-sequence t...
Definition: chew.h:248
line_type
Enumeration of types of input lines.
Definition: line_type.h:52
static void erase_all()
Forget all directives table used by the operative command.
std::string const & argument() const
Get the body of the directive.
Definition: directive.h:158