22 #ifndef __stir_KEYPARSER_H__ 23 #define __stir_KEYPARSER_H__ 28 #include "boost/any.hpp" 39 typedef std::vector<std::string> ASCIIlist_type;
41 class RegisteredObjectBase;
74 BASICCOORDINATE3D_OF_FLOATS,
75 BASICCOORDINATE3D_OF_ARRAY3D_OF_FLOATS,
93 KeyArgument::type type;
96 void* p_object_variable;
97 int vectorised_key_level;
98 const ASCIIlist_type* p_object_list_of_values;
110 const int vectorised_key_level,
111 const ASCIIlist_type* list_of_valid_keywords = 0);
164 typedef std::vector<int> IntVect;
165 typedef std::vector<double> DoubleVect;
173 bool parse(std::istream& f,
const bool write_warnings =
true);
176 bool parse(
const char*
const filename,
const bool write_warnings =
true);
178 bool parse(
const std::string&,
const bool write_warnings =
true);
185 void add_key(
const std::string& keyword,
float* variable_ptr);
187 void add_vectorised_key(
const std::string& keyword, std::vector<float>* variable_ptr);
189 void add_key(
const std::string& keyword,
double* variable_ptr);
191 void add_vectorised_key(
const std::string& keyword, std::vector<double>* variable_ptr);
193 void add_vectorised_key(
const std::string& keyword, std::vector<std::vector<double>>* variable_ptr);
196 void add_key(
const std::string& keyword,
int* variable_ptr);
198 void add_key(
const std::string& keyword, std::vector<int>* variable_ptr);
200 void add_vectorised_key(
const std::string& keyword, std::vector<int>* variable_ptr);
202 void add_vectorised_key(
const std::string& keyword, std::vector<std::vector<int>>* variable_ptr);
205 void add_key(
const std::string& keyword,
long int* variable_ptr);
208 void add_key(
const std::string& keyword,
unsigned int* variable_ptr);
210 void add_vectorised_key(
const std::string& keyword, std::vector<unsigned int>* variable);
212 void add_key(
const std::string& keyword,
unsigned long* variable_ptr);
214 void add_vectorised_key(
const std::string& keyword, std::vector<unsigned long>* variable_ptr);
218 void add_key(
const std::string& keyword,
bool* variable_ptr);
221 void add_key(
const std::string& keyword, std::vector<double>* variable_ptr);
224 void add_key(
const std::string& keyword, std::vector<std::string>* variable_ptr);
227 void add_key(
const std::string& keyword,
Array<2, float>* variable_ptr);
230 void add_key(
const std::string& keyword,
Array<3, float>* variable_ptr);
240 void add_key(
const std::string& keyword, std::string* variable_ptr);
243 void add_vectorised_key(
const std::string& keyword, std::vector<std::string>* variable_ptr);
252 void add_key(
const std::string& keyword,
int* variable_ptr,
const ASCIIlist_type*
const list_of_values);
255 void ignore_key(
const std::string& keyword);
258 void add_start_key(
const std::string& keyword);
260 void add_stop_key(
const std::string& keyword);
302 template <
typename ParsingClass>
303 void add_parsing_key(
const std::string& keyword, ParsingClass** parsed_object_ptr_ptr)
305 add_in_keymap(keyword,
307 reinterpret_cast<RegisteredObjectBase**>(parsed_object_ptr_ptr),
308 (map_element::Parser*)(&ParsingClass::read_registered_object)));
313 template <
typename ParsingClass>
314 void add_parsing_key(
const std::string& keyword, shared_ptr<ParsingClass>* parsed_object_ptr_ptr)
316 add_in_keymap(keyword,
318 reinterpret_cast<shared_ptr<RegisteredObjectBase>*
>(parsed_object_ptr_ptr),
319 (map_element::Parser*)(&ParsingClass::read_registered_object)));
324 bool remove_key(
const std::string& keyword);
331 void add_alias_key(
const std::string& keyword,
const std::string& alias,
bool deprecated_key =
true);
333 void print_keywords_to_stream(std::ostream&)
const;
340 virtual std::string parameter_info()
const;
352 virtual void ask_parameters();
358 int find_in_ASCIIlist(
const std::string&,
const ASCIIlist_type& list_of_values);
373 virtual std::string standardise_keyword(
const std::string& keyword)
const;
378 virtual std::string get_keyword(
const std::string&)
const;
380 typedef void (
KeyParser::*KeywordProcessor)();
388 void add_key(
const std::string& keyword,
390 KeywordProcessor
function,
392 const ASCIIlist_type*
const list = 0);
398 void add_key(
const std::string& keyword,
400 KeywordProcessor
function,
402 const int vectorised_key_level,
403 const ASCIIlist_type*
const list = 0);
407 void add_key(
const std::string& keyword, KeyArgument::type t,
void* variable,
const ASCIIlist_type*
const list = 0);
410 void add_key(
const std::string& keyword,
413 const int vectorised_key_level,
414 const ASCIIlist_type*
const list = 0);
419 void start_parsing();
431 void set_parsing_object();
435 void set_shared_parsing_object();
450 typedef std::list<std::pair<std::string, map_element>> Keymap;
455 typedef std::map<std::string, std::string> AliasMap;
458 AliasMap deprecated_alias_map;
461 map_element* find_in_keymap(
const std::string& keyword);
462 void add_in_keymap(
const std::string& keyword,
const map_element& new_element);
465 std::string resolve_alias(
const std::string& keyword)
const;
475 bool keyword_has_a_value;
476 boost::any parameter;
481 static void value_to_stream(std::ostream& s,
const map_element&);
483 static void vectorised_value_to_stream(std::ostream& s,
const std::string& keyword,
const map_element& element);
486 Succeeded parse_header(
const bool write_warnings);
489 Succeeded read_and_parse_line(
const bool write_warning);
495 Succeeded parse_value_in_line(
const std::string& line,
const bool write_warning);
499 Succeeded map_keyword(
const std::string& keyword);
void add_parsing_key(const std::string &keyword, ParsingClass **parsed_object_ptr_ptr)
add keyword corresponding to an object that will parse the next keys itself
Definition: KeyParser.h:303
A class to parse Interfile headers.
Definition: KeyParser.h:161
Class to store the Interfile keywords and their actions.
Definition: KeyParser.h:90
virtual bool post_processing()
This will be called at the end of the parsing.
Definition: KeyParser.h:368
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
defines the Array class for multi-dimensional (numeric) arrays
A class that enumerates the possible types that can be used to store parsed values. Used (only) by KeyParser.
Definition: KeyParser.h:55
void do_nothing()
callback function for keys which do not do anything
Definition: KeyParser.h:423
Base class for all classes that can parse .par files (and more?)The only reason that this class exist...
Definition: RegisteredObjectBase.h:40
void add_parsing_key(const std::string &keyword, shared_ptr< ParsingClass > *parsed_object_ptr_ptr)
add keyword corresponding to an object that will parse the next keys itself
Definition: KeyParser.h:314
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition: BasicCoordinate.h:53
Declaration of stir::warning()
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43