Mantid
Loading...
Searching...
No Matches
PropertyManager.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11#include "MantidJson/Json.h"
18
19#include <json/json.h>
20
21namespace Mantid::Kernel {
22
23using std::string;
24
25namespace {
26// static logger reference
27Logger g_log("PropertyManager");
28
34const std::string createKey(const std::string &name) {
35 std::string key = name;
36 std::transform(key.begin(), key.end(), key.begin(), toupper);
37 return key;
38}
39} // namespace
40
41const std::string PropertyManager::INVALID_VALUES_SUFFIX = "_invalid_values";
43std::string PropertyManager::getInvalidValuesFilterLogName(const std::string &logName) {
45}
46std::string PropertyManager::getLogNameFromInvalidValuesFilter(const std::string &logName) {
47 std::string retVal = "";
49 retVal = logName.substr(0, logName.size() - PropertyManager::INVALID_VALUES_SUFFIX.size());
50 }
51 return retVal;
52}
53
55bool PropertyManager::isAnInvalidValuesFilterLog(const std::string &logName) {
57 if (logName.length() >= ending.length()) {
58 return (0 == logName.compare(logName.length() - ending.length(), ending.length(), ending));
59 } else {
60 return false;
61 }
62}
63//-----------------------------------------------------------------------------------------------
65PropertyManager::PropertyManager() : m_properties(), m_orderedProperties() {}
66
67//-----------------------------------------------------------------------------------------------
71 : m_properties(), m_orderedProperties(other.m_orderedProperties.size()) {
72 // We need to do a deep copy of the property pointers here
73 for (unsigned int i = 0; i < m_orderedProperties.size(); ++i) {
74 auto p = std::unique_ptr<Property>(other.m_orderedProperties[i]->clone());
75 this->m_orderedProperties[i] = p.get();
76 this->m_properties[createKey(p->name())] = std::move(p);
77 }
78}
79
80//-----------------------------------------------------------------------------------------------
85 // We need to do a deep copy here
86 if (this != &other) {
87 this->m_properties.clear();
88 this->m_orderedProperties.resize(other.m_orderedProperties.size());
89 for (unsigned int i = 0; i < m_orderedProperties.size(); ++i) {
90 auto p = std::unique_ptr<Property>(other.m_orderedProperties[i]->clone());
91 this->m_orderedProperties[i] = p.get();
92 this->m_properties[createKey(p->name())] = std::move(p);
93 }
94 }
95 return *this;
96}
97
98//-----------------------------------------------------------------------------------------------
101
102//-----------------------------------------------------------------------------------------------
109 // Iterate through all properties on the RHS
110 PropertyMap::const_iterator it;
111 for (it = rhs.m_properties.begin(); it != rhs.m_properties.end(); ++it) {
112 // The name on the rhs
113 string rhs_name = it->first;
114 try {
115 Property *lhs_prop = this->getPointerToProperty(rhs_name);
116 // Use the property's += operator to add THAT. Isn't abstraction fun?!
117 (*lhs_prop) += it->second.get();
118 } catch (Exception::NotFoundError &) {
119 // The property isnt on the lhs.
120 // Let's copy it
121 auto copy = std::unique_ptr<Property>(it->second->clone());
122 // And we add a copy of that property to *this
123 this->declareProperty(std::move(copy), "");
124 }
125 }
126
127 return *this;
128}
129
130//-----------------------------------------------------------------------------------------------
139 const std::vector<std::string> &excludedFromFiltering) {
140 auto filter = logFilter->filter();
141 for (auto &orderedProperty : m_orderedProperties) {
142 // cppcheck-suppress invalidLifetime
143 std::string const propName = orderedProperty->name();
144 if (std::find(excludedFromFiltering.cbegin(), excludedFromFiltering.cend(), propName) !=
145 excludedFromFiltering.cend()) {
146 // this log should be excluded from filtering
147 continue;
148 }
149
150 if (auto doubleSeries = dynamic_cast<TimeSeriesProperty<double> *>(orderedProperty)) {
151 // don't filter the invalid values filters
153 break;
154 std::unique_ptr<Property> filtered(nullptr);
156
157 // combine this log's invalid values filter with a copy of the passed in filter
159 auto const *tspFilterProp = dynamic_cast<TimeSeriesProperty<bool> const *>(filterProp);
160 if (!tspFilterProp)
161 break;
162 LogFilter propFilter(*filter);
163 propFilter.addFilter(*tspFilterProp);
164
165 filtered = std::make_unique<FilteredTimeSeriesProperty<double>>(doubleSeries, *propFilter.filter());
166 } else if (filter->size() > 0) {
167 // attach the filter to the TimeSeriesProperty, thus creating the FilteredTimeSeriesProperty<double>
168 filtered = std::make_unique<FilteredTimeSeriesProperty<double>>(doubleSeries, *filter);
169 }
170 if (filtered) {
171 // Now replace in the map
172 orderedProperty = filtered.get();
173 this->m_properties[createKey(propName)] = std::move(filtered);
174 }
175 }
176 }
177}
178
188 PropertyManager *newMgr = new PropertyManager();
189 newMgr->m_orderedProperties.reserve(m_orderedProperties.size());
190 // We need to do a deep copy of the property pointers here
191 for (auto const *prop : m_orderedProperties) {
192 std::unique_ptr<Property> newProp;
193 if (auto const *tsp = dynamic_cast<ITimeSeriesProperty const *>(prop))
194 newProp = std::unique_ptr<Property>(tsp->cloneInTimeROI(timeROI));
195 else
196 newProp = std::unique_ptr<Property>(prop->clone());
197 newMgr->m_orderedProperties.emplace_back(newProp.get());
198 newMgr->m_properties[createKey(newProp->name())] = std::move(newProp);
199 }
200 return newMgr;
201}
202
209 for (auto prop : m_orderedProperties) {
210 if (auto tsp = dynamic_cast<ITimeSeriesProperty *>(prop))
211 tsp->removeDataOutsideTimeROI(timeROI);
212 }
213}
214
215//-----------------------------------------------------------------------------------------------
223void PropertyManager::declareProperty(std::unique_ptr<Property> p, const std::string &doc) {
224 p->setDocumentation(doc);
225
226 const std::string key = createKey(p->name());
227 auto existing = m_properties.find(key);
228 if (existing == m_properties.end()) {
229 m_orderedProperties.emplace_back(p.get());
230 m_properties[key] = std::move(p);
231 } else {
232 // Don't error if this is actually the same property object!
233 if (existing->second != p) {
234 throw Exception::ExistsError("Property with given name already exists", key);
235 }
236 }
237}
238
244void PropertyManager::declareOrReplaceProperty(std::unique_ptr<Property> p, const std::string &doc) {
245 p->setDocumentation(doc);
246
247 const std::string key = createKey(p->name());
248 auto existing = m_properties.find(key);
249 if (existing != std::end(m_properties)) {
250 // replace it in the same position
251 auto oldPropPtr = existing->second.get();
252 auto ordereredPropPos = std::find(std::begin(m_orderedProperties), std::end(m_orderedProperties), oldPropPtr);
253 // if the property exists it should be guaranteed to be in the ordered list
254 // by declareProperty
255 assert(ordereredPropPos != std::end(m_orderedProperties));
256 *ordereredPropPos = p.get();
257 } else {
258 m_orderedProperties.emplace_back(p.get());
259 }
260 m_properties[key] = std::move(p);
261}
262
266 for (auto &prop : getProperties()) {
267 if (!prop->isDefault())
268 prop->setValue(prop->getDefault());
269 }
270}
271
272//-----------------------------------------------------------------------------------------------
284void PropertyManager::setProperties(const std::string &propertiesJson,
285 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
286 setProperties(propertiesJson, this, ignoreProperties, createMissing);
287}
288//-----------------------------------------------------------------------------------------------
302void PropertyManager::setProperties(const std::string &propertiesJson, IPropertyManager *targetPropertyManager,
303 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
304 ::Json::Value jsonValue;
305
306 if (Mantid::JsonHelpers::parse(propertiesJson, &jsonValue)) {
307 setProperties(jsonValue, targetPropertyManager, ignoreProperties, createMissing);
308 } else {
309 throw std::invalid_argument("propertiesArray was not valid json");
310 }
311}
312//-----------------------------------------------------------------------------------------------
320void PropertyManager::setProperties(const ::Json::Value &jsonValue,
321 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
322 setProperties(jsonValue, this, ignoreProperties, createMissing);
323}
324
325//-----------------------------------------------------------------------------------------------
335void PropertyManager::setProperties(const ::Json::Value &jsonValue, IPropertyManager *targetPropertyManager,
336 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
337 if (jsonValue.type() != ::Json::ValueType::objectValue)
338 return;
339
340 // Some algorithms require Filename to be set first do that here
341 static const std::string propFilename = "Filename";
342 const ::Json::Value &filenameValue = jsonValue[propFilename];
343 if (!filenameValue.isNull()) {
344 const std::string value = filenameValue.asString();
345 // Set it
346 targetPropertyManager->setPropertyValue(propFilename, value);
347 }
348 const auto memberNames = jsonValue.getMemberNames();
349 for (::Json::ArrayIndex i = 0; i < jsonValue.size(); i++) {
350 const auto &propName = memberNames[i];
351 if ((propFilename == propName) || (ignoreProperties.find(propName) != ignoreProperties.end())) {
352 continue;
353 }
354 const ::Json::Value &propValue = jsonValue[propName];
355 if (createMissing) {
356 targetPropertyManager->declareOrReplaceProperty(decodeAsProperty(propName, propValue));
357 } else {
358 targetPropertyManager->setPropertyValueFromJson(propName, propValue);
359 }
360 }
361}
362
369void PropertyManager::setPropertiesWithString(const std::string &propertiesString,
370 const std::unordered_set<std::string> &ignoreProperties) {
371 if (propertiesString.empty()) {
372 return;
373 }
374 auto firstSymbol = propertiesString.find_first_not_of(" \n\t");
375 if (firstSymbol == std::string::npos) {
376 return;
377 }
378 if (propertiesString[firstSymbol] == '{') {
379 setPropertiesWithJSONString(propertiesString, ignoreProperties);
380 } else {
381 setPropertiesWithSimpleString(propertiesString, ignoreProperties);
382 }
383}
384
390void PropertyManager::setPropertiesWithJSONString(const std::string &propertiesString,
391 const std::unordered_set<std::string> &ignoreProperties) {
392 ::Json::Value propertyJson;
393
394 if (Mantid::JsonHelpers::parse(propertiesString, &propertyJson)) {
395 setProperties(propertyJson, ignoreProperties);
396 } else {
397 throw std::invalid_argument("Could not parse JSON string when trying to set a property from: " + propertiesString);
398 }
399}
400
407void PropertyManager::setPropertiesWithSimpleString(const std::string &propertiesString,
408 const std::unordered_set<std::string> &ignoreProperties) {
409 ::Json::Value propertyJson;
410 // Split up comma-separated properties
412
413 boost::char_separator<char> sep(";");
414 tokenizer propPairs(propertiesString, ";", Mantid::Kernel::StringTokenizer::TOK_TRIM);
415 // Iterate over the properties
416 for (const auto &pair : propPairs) {
417 size_t n = pair.find('=');
418 if (n != std::string::npos) {
419 // Normal "PropertyName=value" string.
420 std::string propName;
421 std::string value;
422
423 // Extract the value string
424 if (n < pair.size() - 1) {
425 propName = pair.substr(0, n);
426 value = pair.substr(n + 1, pair.size() - n - 1);
427 } else {
428 // String is "PropertyName="
429 propName = pair.substr(0, n);
430 value = "";
431 }
432 // Set it
433 propertyJson[propName] = value;
434 }
435 }
436 setProperties(propertyJson, ignoreProperties);
437}
438
439//-----------------------------------------------------------------------------------------------
448void PropertyManager::setPropertyValue(const std::string &name, const std::string &value) {
449 auto *prop = getPointerToProperty(name);
450 auto helpMsg = prop->setValue(value);
452 if (!helpMsg.empty()) {
453 helpMsg = "Invalid value for property " + prop->name() + " (" + prop->type() + ") from string \"" + value +
454 "\": " + helpMsg;
455 throw std::invalid_argument(helpMsg);
456 }
457}
458
466void PropertyManager::setPropertyValueFromJson(const std::string &name, const Json::Value &value) {
467 auto *prop = getPointerToProperty(name);
468 auto helpMsg = prop->setValueFromJson(value);
470 if (!helpMsg.empty()) {
471 helpMsg = "Invalid value for property " + prop->name() + " (" + prop->type() + ") from Json \"" +
472 value.toStyledString() + "\": " + helpMsg;
473 throw std::invalid_argument(helpMsg);
474 }
475}
476
477//-----------------------------------------------------------------------------------------------
486void PropertyManager::setPropertyOrdinal(const int &index, const std::string &value) {
487 Property *p = getPointerToPropertyOrdinal(index); // throws runtime_error if property not in vector
488 std::string errorMsg = p->setValue(value);
489 this->afterPropertySet(p->name());
490 if (!errorMsg.empty()) {
491 errorMsg = "Invalid value for property " + p->name() + " (" + p->type() + ") \"" + value + "\" : " + errorMsg;
492 throw std::invalid_argument(errorMsg);
493 }
494}
495
496//-----------------------------------------------------------------------------------------------
502bool PropertyManager::existsProperty(const std::string &name) const {
503 const std::string key = createKey(name);
504 auto it = m_properties.find(key);
505 return (it != m_properties.end());
506}
507
508//-----------------------------------------------------------------------------------------------
513 bool allValid = true;
514 for (const auto &property : m_properties) {
515 // check for errors in each property
516 std::string error = property.second->isValid();
517 //"" means no error
518 if (!error.empty()) {
519 g_log.error() << "Property \"" << property.first << "\" is not set to a valid value: \"" << error << "\".\n";
520 allValid = false;
521 }
522 }
523 return allValid;
524}
525
526//-----------------------------------------------------------------------------------------------
532
533//-----------------------------------------------------------------------------------------------
539std::string PropertyManager::getPropertyValue(const std::string &name) const {
540 Property const *p = getPointerToProperty(name); // throws NotFoundError if property not in vector
541 return p->value();
542}
543
544//-----------------------------------------------------------------------------------------------
552std::string PropertyManager::asString(bool withDefaultValues) const {
553 Json::StreamWriterBuilder builder;
554 builder.settings_["indentation"] = "";
555 const string output = Json::writeString(builder, asJson(withDefaultValues));
556
557 return output;
558}
559
560//-----------------------------------------------------------------------------------------------
566::Json::Value PropertyManager::asJson(bool withDefaultValues) const {
567 ::Json::Value jsonMap;
568 const auto count = static_cast<int>(propertyCount());
569 for (int i = 0; i < count; ++i) {
571 if (isPropertyEnabled(p->name()) && p->isValueSerializable() && (withDefaultValues || !p->isDefault())) {
572 jsonMap[p->name()] = p->valueAsJson();
573 }
574 }
575
576 return jsonMap;
577}
578
580 if (other.m_properties.size() != m_properties.size())
581 return false;
582 for (const auto &[key, value] : m_properties) {
583 if (other.m_properties.count(key) != 1)
584 return false;
585 if (*other.m_properties.at(key) != *value)
586 return false;
587 }
588 return true;
589}
590
591bool PropertyManager::operator!=(const PropertyManager &other) const { return !this->operator==(other); }
592
593//-----------------------------------------------------------------------------------------------
600 const std::string key = createKey(name);
601 auto it = m_properties.find(key);
602 if (it != m_properties.end()) {
603 return it->second.get();
604 }
605 throw Exception::NotFoundError("Unknown property", name);
606}
607
608//-----------------------------------------------------------------------------------------------
614 const std::string key = createKey(name);
615 auto it = m_properties.find(key);
616 if (it != m_properties.end()) {
617 return it->second.get();
618 }
619 return nullptr;
620}
621
622//-----------------------------------------------------------------------------------------------
629
630 if (index < static_cast<int>(m_orderedProperties.size())) {
632 }
633 throw std::runtime_error("Property index too high");
634}
635
636//-----------------------------------------------------------------------------------------------
641const std::vector<Property *> &PropertyManager::getProperties() const { return m_orderedProperties; }
642
643//-----------------------------------------------------------------------------------------------
648std::vector<std::string> PropertyManager::getDeclaredPropertyNames() const noexcept {
649 std::vector<std::string> names;
650 const auto &props = getProperties();
651 names.reserve(props.size());
652 std::transform(props.cbegin(), props.cend(), std::back_inserter(names),
653 [](auto &propPtr) { return propPtr->name(); });
654 return names;
655}
656
657//-----------------------------------------------------------------------------------------------
675 return TypedValue(*this, name);
676}
677
678//-----------------------------------------------------------------------------------------------
683void PropertyManager::removeProperty(const std::string &name, const bool delproperty) {
684 if (existsProperty(name)) {
685 // remove it
687 const std::string key = createKey(name);
688 m_properties.erase(key);
689 std::vector<Property *>::iterator itr;
690 itr = find(m_orderedProperties.begin(), m_orderedProperties.end(), prop);
691 m_orderedProperties.erase(itr);
692 (void)delproperty; // not used
693 }
694}
695
701std::unique_ptr<Property> PropertyManager::takeProperty(const size_t index) {
702 try {
703 auto const *property = m_orderedProperties[index];
704 const std::string key = createKey(property->name());
705 auto propertyPtr = std::move(m_properties[key]);
706 m_properties.erase(key);
708 return propertyPtr;
709 } catch (const std::out_of_range &) {
710 return NULL;
711 }
712}
713
714//-----------------------------------------------------------------------------------------------
719 m_orderedProperties.clear();
720 m_properties.clear();
721}
722
723//-----------------------------------------------------------------------------------------------
729Json::Value encodeAsJson(const PropertyManager &propMgr) { return propMgr.asJson(true); }
730
731} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
const std::vector< double > & rhs
double value
The value of the point.
Definition FitMW.cpp:51
double error
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
Exception for when an item is already in a collection.
Definition Exception.h:164
Exception for when an item is not found in a collection.
Definition Exception.h:145
Interface to PropertyManager.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
virtual void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
virtual void afterPropertySet(const std::string &)
Override this method to perform a custom action right after a property was set.
bool isPropertyEnabled(const std::string &name) const
Test if a given property should be enabled.
virtual void setPropertyValueFromJson(const std::string &name, const Json::Value &value)=0
Sets property value from a Json::Value.
A non-templated interface to a TimeSeriesProperty.
This class is for filtering TimeSeriesProperty data.
Definition LogFilter.h:32
const TimeSeriesProperty< bool > * filter() const
Returns a reference to the filter.
Definition LogFilter.h:55
void addFilter(const TimeSeriesProperty< bool > &filter)
Adds a filter using boolean AND.
Definition LogFilter.cpp:64
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
Property manager helper class.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void clear() override final
Clears the whole property map.
bool operator!=(const PropertyManager &other) const
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
bool validateProperties() const override
Validates all the properties in the collection.
void removeProperty(const std::string &name, const bool delproperty=true) override
removes the property from properties map
void setPropertyOrdinal(const int &index, const std::string &value) override
Set the value of a property by an index N.B.
void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add or replace a property in the list of managed properties.
size_t propertyCount() const override
Count the number of properties under management.
PropertyManager & operator+=(const PropertyManager &rhs)
Addition operator.
PropertyManager()
Default constructor.
void resetProperties() override
Reset property values back to initial values (blank or default values)
Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
Set the ordered list of properties by one string of values, separated by semicolons.
void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
Sets all the declared properties from a string.
PropertyMap m_properties
The properties under management.
void removeDataOutsideTimeROI(const Kernel::TimeROI &timeROI)
For time series properties, remove time values outside of TimeROI regions, each defined as [roi_begin...
std::string asString(bool withDefaultValues=false) const override
Return the property manager serialized as a string.
void setPropertiesWithJSONString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties)
Sets all the declared properties from a string.
static bool isAnInvalidValuesFilterLog(const std::string &logName)
Determine if the log's name has a substring indicating it should not be filtered.
void setPropertiesWithSimpleString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties)
Sets all the declared properties from a string.
static std::string getInvalidValuesFilterLogName(const std::string &logName)
Gets the correct log name for the matching invalid values log for a given log name.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
std::unique_ptr< Property > takeProperty(const size_t index) override
removes the property from the properties map and returns a pointer to it
static std::string getLogNameFromInvalidValuesFilter(const std::string &logName)
void filterByProperty(Mantid::Kernel::LogFilter *logFilter, const std::vector< std::string > &excludedFromFiltering=std::vector< std::string >()) override
Filter the managed properties by the given boolean property mask.
Property * getPointerToPropertyOrdinal(const int &index) const override
Get a property by an index.
::Json::Value asJson(bool withDefaultValues=false) const override
Return the property manager serialized as a json object.
Property * getPointerToPropertyOrNull(const std::string &name) const
Get a property by name.
std::vector< Property * > m_orderedProperties
Stores the order in which the properties were declared.
void declareProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
PropertyManager & operator=(const PropertyManager &)
Assignment operator - performs a deep copy.
bool operator==(const PropertyManager &other) const
void setPropertyValueFromJson(const std::string &name, const Json::Value &value) override
Set the value of a property by Json::Value.
static const std::string INVALID_VALUES_SUFFIX
const std::vector< Property * > & getProperties() const override
Get the list of managed properties.
PropertyManager * cloneInTimeROI(const Kernel::TimeROI &timeROI)
Create a partial copy of this object such that every time series property is cloned according to the ...
virtual ~PropertyManager() override
Virtual destructor.
std::vector< std::string > getDeclaredPropertyNames() const noexcept override
Return the list of declared property names.
Base class for properties.
Definition Property.h:95
virtual std::string setValue(const std::string &)=0
Set the value of the property via a string.
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
const std::string & name() const
Get the property's name.
Definition Property.cpp:63
const std::string type() const
Returns the type of the property as a string.
Definition Property.cpp:89
virtual Json::Value valueAsJson() const =0
Returns the value of the property as a Json::Value.
virtual std::string value() const =0
Returns the value of the property as a string.
virtual bool isValueSerializable() const
Whether the string returned by value() can be used for serialization.
Definition Property.h:143
@ TOK_TRIM
remove leading and trailing whitespace from tokens
TimeROI : Object that holds information about when the time measurement was active.
Definition TimeROI.h:18
A specialised Property class for holding a series of time-value pairs.
MANTID_KERNEL_DLL std::unique_ptr< Property > decodeAsProperty(const std::string &name, const Json::Value &value)
Attempt to create a Property of the most appropriate type from a string name and Json value object.
MANTID_KERNEL_DLL::Json::Value encodeAsJson(const OptionalBool &)
Encode an OptionalBool as a Json::Value.
Utility class that enables the getProperty() method to effectively be templated on the return type.