-
-
Notifications
You must be signed in to change notification settings - Fork 993
/
key.hpp
143 lines (116 loc) · 2.51 KB
/
key.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (C) 2011 - 2018 by Sytyi Nick <nsytyi@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* This file contains object "key", which is used to store
* information about keys while annotation parsing.
*/
#pragma once
#include <iosfwd>
#include <string>
class config;
namespace schema_validation
{
/**
* class_key is used to save the information about one key.
* Key has next info: name, type, default value or key is mandatory.
*/
class class_key
{
public:
class_key()
: name_("")
, type_("")
, default_("\"\"")
, mandatory_(false)
, fuzzy_(false)
{
}
class_key(const std::string& name, const std::string& type, const std::string& def = "\"\"")
: name_(name)
, type_(type)
, default_(def)
, mandatory_(def.empty())
, fuzzy_(name.find_first_of("*?") != std::string::npos)
{
}
class_key(const config&);
const std::string& get_name() const
{
return name_;
}
const std::string& get_type() const
{
return type_;
}
const std::string& get_default() const
{
return default_;
}
bool is_mandatory() const
{
return mandatory_;
}
bool is_fuzzy() const {
return fuzzy_;
}
void set_name(const std::string& name)
{
name_ = name;
}
void set_type(const std::string& type)
{
type_ = type;
}
void set_default(const std::string& def)
{
default_ = def;
if(def.empty()) {
mandatory_ = true;
}
}
void set_mandatory(bool mandatory)
{
mandatory_ = mandatory;
}
void set_fuzzy(bool f)
{
fuzzy_ = f;
}
/** is used to print key info
* the format is next
* [key]
* name="name"
* type="type"
* default="default"
* mandatory="true/false"
* [/key]
*/
void print(std::ostream& os, int level) const;
/** Compares keys by name. Used in std::sort, i.e. */
bool operator<(const class_key& k) const
{
return (get_name() < k.get_name());
}
private:
/** Name of key. */
std::string name_;
/** Type of key. */
std::string type_;
/** Default value. */
std::string default_;
/** Shows, if key is a mandatory key. */
bool mandatory_;
/** Whether the key is a fuzzy match. */
bool fuzzy_;
};
}