| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4ca0789 commit 778db67
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,7 +148,7 @@ void OptionsParser<Options>::Implies(const std::string& from, | |||
| 148 | 148 | CHECK_NE(it, options_.end()); | |
| 149 | 149 | CHECK_EQ(it->second.type, kBoolean); | |
| 150 | 150 | implications_.emplace(from, Implication { | |
| 151 | - std::static_pointer_cast<OptionField<bool>>(it->second.field), true | ||
| 151 | + it->second.field, true | ||
| 152 | 152 | }); | |
| 153 | 153 | } | |
| 154 | 154 | ||
@@ -159,7 +159,7 @@ void OptionsParser<Options>::ImpliesNot(const std::string& from, | |||
| 159 | 159 | CHECK_NE(it, options_.end()); | |
| 160 | 160 | CHECK_EQ(it->second.type, kBoolean); | |
| 161 | 161 | implications_.emplace(from, Implication { | |
| 162 | - std::static_pointer_cast<OptionField<bool>>(it->second.field), false | ||
| 162 | + it->second.field, false | ||
| 163 | 163 | }); | |
| 164 | 164 | } | |
| 165 | 165 | ||
@@ -205,8 +205,7 @@ auto OptionsParser<Options>::Convert( | |||
| 205 | 205 | typename OptionsParser<ChildOptions>::Implication original, | |
| 206 | 206 | ChildOptions* (Options::* get_child)()) { | |
| 207 | 207 | return Implication { | |
| 208 | - std::static_pointer_cast<OptionField<bool>>( | ||
| 209 | - Convert(original.target_field, get_child)), | ||
| 208 | + Convert(original.target_field, get_child), | ||
| 210 | 209 | original.target_value | |
| 211 | 210 | }; | |
| 212 | 211 | } | |
@@ -378,8 +377,10 @@ void OptionsParser<Options>::Parse( | |||
| 378 | 377 | ||
| 379 | 378 | { | |
| 380 | 379 | auto implications = implications_.equal_range(name); | |
| 381 | - for (auto it = implications.first; it != implications.second; ++it) | ||
| 382 | - *it->second.target_field->Lookup(options) = it->second.target_value; | ||
| 380 | + for (auto it = implications.first; it != implications.second; ++it) { | ||
| 381 | + *it->second.target_field->template Lookup<bool>(options) = | ||
| 382 | + it->second.target_value; | ||
| 383 | + } | ||
| 383 | 384 | } | |
| 384 | 385 | ||
| 385 | 386 | const OptionInfo& info = it->second; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -336,23 +336,17 @@ class OptionsParser { | |||
| 336 | 336 | public: | |
| 337 | 337 | virtual ~BaseOptionField() {} | |
| 338 | 338 | virtual void* LookupImpl(Options* options) const = 0; | |
| 339 | - }; | ||
| 340 | - | ||
| 341 | - // Represents a field of type T within `Options`. | ||
| 342 | - template <typename T> | ||
| 343 | - class OptionField : public BaseOptionField { | ||
| 344 | - public: | ||
| 345 | - typedef T Type; | ||
| 346 | 339 | ||
| 347 | - T* Lookup(Options* options) const { | ||
| 348 | - return static_cast<T*>(this->LookupImpl(options)); | ||
| 340 | + template <typename T> | ||
| 341 | + inline T* Lookup(Options* options) const { | ||
| 342 | + return static_cast<T*>(LookupImpl(options)); | ||
| 349 | 343 | } | |
| 350 | 344 | }; | |
| 351 | 345 | ||
| 352 | 346 | // Represents a field of type T within `Options` that can be looked up | |
| 353 | 347 | // as a C++ member field. | |
| 354 | 348 | template <typename T> | |
| 355 | - class SimpleOptionField : public OptionField<T> { | ||
| 349 | + class SimpleOptionField : public BaseOptionField { | ||
| 356 | 350 | public: | |
| 357 | 351 | explicit SimpleOptionField(T Options::* field) : field_(field) {} | |
| 358 | 352 | void* LookupImpl(Options* options) const override { | |
@@ -366,7 +360,7 @@ class OptionsParser { | |||
| 366 | 360 | template <typename T> | |
| 367 | 361 | inline T* Lookup(std::shared_ptr<BaseOptionField> field, | |
| 368 | 362 | Options* options) const { | |
| 369 | - return std::static_pointer_cast<OptionField<T>>(field)->Lookup(options); | ||
| 363 | + return field->template Lookup<T>(options); | ||
| 370 | 364 | } | |
| 371 | 365 | ||
| 372 | 366 | // An option consists of: | |
@@ -383,7 +377,7 @@ class OptionsParser { | |||
| 383 | 377 | // An implied option is composed of the information on where to store a | |
| 384 | 378 | // specific boolean value (if another specific option is encountered). | |
| 385 | 379 | struct Implication { | |
| 386 | - std::shared_ptr<OptionField<bool>> target_field; | ||
| 380 | + std::shared_ptr<BaseOptionField> target_field; | ||
| 387 | 381 | bool target_value; | |
| 388 | 382 | }; | |
| 389 | 383 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments