Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef SCHEMA_VALIDATOR_HPP
00017 #define SCHEMA_VALIDATOR_HPP
00018
00019 #include "serialization/validator.hpp"
00020 #include "tools/schema/tag.hpp"
00021
00022 #include "config.hpp"
00023 #include "config_cache.hpp"
00024 #include "serialization/parser.hpp"
00025
00026
00027
00028 #include "boost/regex.hpp"
00029
00030 #include <iostream>
00031 #include <queue>
00032 #include <string>
00033 #include <stack>
00034
00035
00036
00037
00038 namespace schema_validation{
00039
00040
00041
00042
00043 class schema_validator : public abstract_validator{
00044 public:
00045 virtual ~schema_validator();
00046
00047
00048
00049
00050 schema_validator(const std::string & filename);
00051 void set_create_exceptions(bool value){
00052 create_exceptions_ = value;
00053 }
00054
00055 virtual void open_tag(const std::string & name,
00056 int start_line=0,
00057 const std::string &file="",
00058 bool addittion = false);
00059 virtual void close_tag();
00060 virtual void validate(const config & cfg,
00061 const std::string & name,
00062 int start_line,
00063 const std::string &file);
00064 virtual void validate_key(const config & cfg,
00065 const std::string & name,
00066 const std::string & value,
00067 int start_line,
00068 const std::string &file);
00069 private:
00070
00071
00072 struct counter{
00073 int cnt;
00074 counter(): cnt(0){}
00075 };
00076
00077
00078
00079 typedef std::map<std::string,counter> cnt_map;
00080
00081
00082
00083
00084 typedef std::stack<cnt_map> cnt_stack;
00085
00086 enum message_type{WRONG_TAG,EXTRA_TAG,MISSING_TAG,
00087 EXTRA_KEY,MISSING_KEY,WRONG_VALUE};
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 struct message_info{
00099 message_type type;
00100 std::string file;
00101 int line;
00102 int n;
00103 std::string tag;
00104 std::string key;
00105 std::string value;
00106 message_info(message_type t,
00107 const std::string& file,
00108 int line = 0,
00109 int n = 0,
00110 const std::string& tag = "",
00111 const std::string& key = "",
00112 const std::string& value = "")
00113 :type(t),file(file),line(line),n(n),tag(tag),key(key),
00114 value(value){}
00115 };
00116 typedef std::deque<message_info> message_list;
00117 typedef std::map<const config *, message_list> message_map;
00118
00119 void print(message_info &);
00120
00121
00122
00123 bool read_config_file(const std::string & filename);
00124
00125
00126
00127 bool config_read_;
00128
00129
00130
00131 bool create_exceptions_;
00132
00133
00134
00135 class_tag root_;
00136
00137 std::stack<const class_tag *> stack_;
00138
00139
00140
00141 cnt_stack counter_;
00142
00143
00144
00145 std::stack<message_map> cache_;
00146
00147
00148
00149 std::map<std::string,boost::regex> types_;
00150 };
00151 }
00152
00153 #endif // SCHEMA_VALIDATOR_HPP