OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
infoselectwrapper.hpp
Go to the documentation of this file.
1 #ifndef CSM_WORLD_INFOSELECTWRAPPER_H
2 #define CSM_WORLD_INFOSELECTWRAPPER_H
3 
5 
6 namespace CSMWorld
7 {
8  // ESM::DialInfo::SelectStruct.mSelectRule
9  // 012345...
10  // ^^^ ^^
11  // ||| ||
12  // ||| |+------------- condition variable string
13  // ||| +-------------- comparison type, ['0'..'5']; e.g. !=, <, >=, etc
14  // ||+---------------- function index (encoded, where function == '1')
15  // |+----------------- function, ['1'..'C']; e.g. Global, Local, Not ID, etc
16  // +------------------ unknown
17  //
18 
19  // Wrapper for DialInfo::SelectStruct
21  {
22  public:
23 
24  // Order matters
26  {
101 
113 
115  };
116 
118  {
125 
127  };
128 
130  {
134 
136  };
137 
138  static const size_t RuleMinSize;
139 
140  static const size_t FunctionPrefixOffset;
141  static const size_t FunctionIndexOffset;
142  static const size_t RelationIndexOffset;
143  static const size_t VarNameOffset;
144 
145  static const char* FunctionEnumStrings[];
146  static const char* RelationEnumStrings[];
147  static const char* ComparisonEnumStrings[];
148 
149  static std::string convertToString(FunctionName name);
150  static std::string convertToString(RelationType type);
151  static std::string convertToString(ComparisonType type);
152 
154 
158 
159  bool hasVariable() const;
160  const std::string& getVariableName() const;
161 
162  bool conditionIsAlwaysTrue() const;
163  bool conditionIsNeverTrue() const;
164  bool variantTypeIsValid() const;
165 
166  const ESM::Variant& getVariant() const;
167 
168  std::string toString() const;
169 
170  protected:
171 
172  void readRule();
173  void readFunctionName();
174  void readRelationType();
175  void readVariableName();
176  void updateHasVariable();
177  void updateComparisonType();
178 
179  std::pair<int, int> getConditionIntRange() const;
180  std::pair<float, float> getConditionFloatRange() const;
181 
182  std::pair<int, int> getValidIntRange() const;
183  std::pair<float, float> getValidFloatRange() const;
184 
185  template <typename Type1, typename Type2>
186  bool rangeContains(Type1 value, std::pair<Type2,Type2> range) const;
187 
188  template <typename Type1, typename Type2>
189  bool rangesOverlap(std::pair<Type1,Type1> range1, std::pair<Type2,Type2> range2) const;
190 
191  template <typename Type1, typename Type2>
192  bool rangeFullyContains(std::pair<Type1,Type1> containing, std::pair<Type2,Type2> test) const;
193 
194  template <typename Type1, typename Type2>
195  bool rangesMatch(std::pair<Type1,Type1> range1, std::pair<Type2,Type2> range2) const;
196 
197  template <typename Type1, typename Type2>
198  bool conditionIsAlwaysTrue(std::pair<Type1,Type1> conditionRange, std::pair<Type2,Type2> validRange) const;
199 
200  template <typename Type1, typename Type2>
201  bool conditionIsNeverTrue(std::pair<Type1,Type1> conditionRange, std::pair<Type2,Type2> validRange) const;
202 
206 
208  std::string mVariableName;
209 
210  private:
211 
213  };
214 
215  // Wrapper for DialInfo::SelectStruct that can modify the wrapped select struct
217  {
218  public:
219 
221 
222  // Wrapped SelectStruct will not be modified until update() is called
224  void setRelationType(RelationType type);
225  void setVariableName(const std::string& name);
226 
227  // Modified wrapped SelectStruct
228  void update();
229 
230  // This sets properties based on the function name to its defaults and updates the wrapped object
231  void setDefaults();
232 
234 
235  private:
236 
238 
239  void writeRule();
240  };
241 }
242 
243 #endif
Definition: infoselectwrapper.hpp:114
Definition: infoselectwrapper.hpp:47
std::string mVariableName
Definition: infoselectwrapper.hpp:208
FunctionName
Definition: infoselectwrapper.hpp:25
bool hasVariable() const
Definition: infoselectwrapper.cpp:172
Definition: infoselectwrapper.hpp:120
Definition: infoselectwrapper.hpp:133
Definition: infoselectwrapper.hpp:65
const std::string & getVariableName() const
Definition: infoselectwrapper.cpp:177
std::pair< int, int > getConditionIntRange() const
Definition: infoselectwrapper.cpp:472
bool conditionIsNeverTrue() const
Definition: infoselectwrapper.cpp:205
Definition: infoselectwrapper.hpp:71
bool mHasVariable
Definition: infoselectwrapper.hpp:207
Definition: infoselectwrapper.hpp:95
Definition: infoselectwrapper.hpp:99
void readRule()
Definition: infoselectwrapper.cpp:266
Definition: infoselectwrapper.hpp:39
Definition: infoselectwrapper.hpp:119
Definition: infoselectwrapper.hpp:90
std::pair< int, int > getValidIntRange() const
Definition: infoselectwrapper.cpp:550
Definition: infoselectwrapper.hpp:135
Definition: infoselectwrapper.hpp:82
Definition: infoselectwrapper.hpp:52
Definition: infoselectwrapper.hpp:107
Definition: infoselectwrapper.hpp:94
Definition: infoselectwrapper.hpp:27
ESM::DialInfo::SelectStruct & mSelect
Definition: infoselectwrapper.hpp:237
void setRelationType(RelationType type)
Definition: infoselectwrapper.cpp:800
Definition: infoselectwrapper.hpp:103
Definition: infoselectwrapper.hpp:45
std::pair< float, float > getConditionFloatRange() const
Definition: infoselectwrapper.cpp:518
bool conditionIsAlwaysTrue() const
Definition: infoselectwrapper.cpp:182
Definition: infoselectwrapper.hpp:55
RelationType
Definition: infoselectwrapper.hpp:117
Definition: infoselectwrapper.hpp:37
Definition: infoselectwrapper.hpp:112
Definition: infoselectwrapper.hpp:33
bool rangesOverlap(std::pair< Type1, Type1 > range1, std::pair< Type2, Type2 > range2) const
Definition: infoselectwrapper.hpp:57
static const size_t FunctionPrefixOffset
Definition: infoselectwrapper.hpp:140
bool rangeFullyContains(std::pair< Type1, Type1 > containing, std::pair< Type2, Type2 > test) const
Definition: infoselectwrapper.hpp:93
RelationType getRelationType() const
Definition: infoselectwrapper.cpp:162
Definition: infoselectwrapper.hpp:81
RelationType mRelationType
Definition: infoselectwrapper.hpp:204
Definition: infoselectwrapper.hpp:216
Definition: infoselectwrapper.hpp:50
void update()
Definition: infoselectwrapper.cpp:836
static const char * FunctionEnumStrings[]
Definition: infoselectwrapper.hpp:145
Definition: infoselectwrapper.hpp:35
static std::string convertToString(FunctionName name)
Definition: infoselectwrapper.cpp:125
ESM::Variant & getVariant()
Definition: infoselectwrapper.cpp:890
Definition: infoselectwrapper.hpp:110
bool variantTypeIsValid() const
Definition: infoselectwrapper.cpp:228
InfoSelectWrapper(ESM::DialInfo::SelectStruct &select)
Definition: infoselectwrapper.cpp:788
Definition: infoselectwrapper.hpp:126
static const size_t RelationIndexOffset
Definition: infoselectwrapper.hpp:142
Definition: infoselectwrapper.hpp:108
Definition: infoselectwrapper.hpp:85
Definition: infoselectwrapper.hpp:102
Definition: infoselectwrapper.hpp:109
ComparisonType mComparisonType
Definition: infoselectwrapper.hpp:205
Definition: infoselectwrapper.hpp:84
Definition: infoselectwrapper.hpp:87
static const char * RelationEnumStrings[]
Definition: infoselectwrapper.hpp:146
Definition: infoselectwrapper.hpp:131
void setVariableName(const std::string &name)
Definition: infoselectwrapper.cpp:805
static const size_t FunctionIndexOffset
Definition: infoselectwrapper.hpp:141
Definition: infoselectwrapper.hpp:46
void readVariableName()
Definition: infoselectwrapper.cpp:332
void setFunctionName(FunctionName name)
Definition: infoselectwrapper.cpp:793
ComparisonType
Definition: infoselectwrapper.hpp:129
Definition: infoselectwrapper.hpp:20
Definition: infoselectwrapper.hpp:38
bool rangesMatch(std::pair< Type1, Type1 > range1, std::pair< Type2, Type2 > range2) const
Definition: infoselectwrapper.hpp:124
Definition: infoselectwrapper.hpp:89
void updateComparisonType()
Definition: infoselectwrapper.cpp:364
Definition: infoselectwrapper.hpp:104
Definition: infoselectwrapper.hpp:44
void setDefaults()
Definition: infoselectwrapper.cpp:810
Definition: infoselectwrapper.hpp:111
Definition: infoselectwrapper.hpp:80
const ESM::Variant & getVariant() const
Definition: infoselectwrapper.cpp:233
Definition: loadinfo.hpp:50
Definition: infoselectwrapper.hpp:75
Definition: infoselectwrapper.hpp:36
Definition: infoselectwrapper.hpp:56
Definition: infoselectwrapper.hpp:77
Definition: infoselectwrapper.hpp:106
const ESM::DialInfo::SelectStruct & mConstSelect
Definition: infoselectwrapper.hpp:212
static const char * ComparisonEnumStrings[]
Definition: infoselectwrapper.hpp:147
std::pair< float, float > getValidFloatRange() const
Definition: infoselectwrapper.cpp:676
Definition: infoselectwrapper.hpp:72
Definition: infoselectwrapper.hpp:30
Definition: infoselectwrapper.hpp:79
Definition: infoselectwrapper.hpp:88
void test(const MWWorld::Ptr &actor, int &compiled, int &total, const Compiler::Extensions *extensions, int warningsMode)
Definition: scripttest.cpp:27
Definition: variant.hpp:25
Definition: infoselectwrapper.hpp:54
Definition: infoselectwrapper.hpp:91
Definition: infoselectwrapper.hpp:43
void readRelationType()
Definition: infoselectwrapper.cpp:316
Definition: infoselectwrapper.hpp:76
Definition: infoselectwrapper.hpp:86
void readFunctionName()
Definition: infoselectwrapper.cpp:278
Definition: infoselectwrapper.hpp:28
bool rangeContains(Type1 value, std::pair< Type2, Type2 > range) const
Definition: infoselectwrapper.hpp:61
Definition: infoselectwrapper.hpp:73
Definition: infoselectwrapper.hpp:123
ConstInfoSelectWrapper(const ESM::DialInfo::SelectStruct &select)
Definition: infoselectwrapper.cpp:151
std::string toString() const
Definition: infoselectwrapper.cpp:238
Definition: infoselectwrapper.hpp:105
FunctionName getFunctionName() const
Definition: infoselectwrapper.cpp:157
Definition: infoselectwrapper.hpp:121
ComparisonType getComparisonType() const
Definition: infoselectwrapper.cpp:167
Definition: infoselectwrapper.hpp:97
void updateHasVariable()
Definition: infoselectwrapper.cpp:340
static const size_t RuleMinSize
Definition: infoselectwrapper.hpp:138
Definition: infoselectwrapper.hpp:132
Definition: infoselectwrapper.hpp:66
Definition: infoselectwrapper.hpp:96
static const size_t VarNameOffset
Definition: infoselectwrapper.hpp:143
const char * name
Definition: crashcatcher.cpp:59
FunctionName mFunctionName
Definition: infoselectwrapper.hpp:203