From db255233f758821a96bba012b2141c12dc2f9f51 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Tue, 3 Mar 2020 00:07:08 +0000 Subject: [PATCH] src/Viewer/ViewPropertyEvaluator.*: added getBoolValue(). --- src/Viewer/ViewPropertyEvaluator.cxx | 22 ++++++++++++++++++++++ src/Viewer/ViewPropertyEvaluator.hxx | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/Viewer/ViewPropertyEvaluator.cxx b/src/Viewer/ViewPropertyEvaluator.cxx index f9703e7cd..8c980dd7a 100644 --- a/src/Viewer/ViewPropertyEvaluator.cxx +++ b/src/Viewer/ViewPropertyEvaluator.cxx @@ -498,6 +498,17 @@ namespace ViewPropertyEvaluator { return default_; } + bool getSequenceBoolValue(Sequence& sequence, bool default_) + { + SGPropertyNode* node = getSequenceNode(sequence); + if (node) { + if (node->getStringValue()[0] != 0) { + return node->getBoolValue(); + } + } + return default_; + } + const std::string& getStringValue(const char* spec) { std::shared_ptr sequence = getSequence(spec); @@ -515,6 +526,17 @@ namespace ViewPropertyEvaluator { return ret; } + bool getBoolValue(const char* spec, bool default_) + { + std::shared_ptr sequence = getSequence(spec); + if (sequence->_nodes.size() != 1 || sequence->_nodes.front()->_begin[0] != '(') { + SG_LOG(SG_VIEW, SG_DEBUG, "bad sequence for getBoolValue() - must have outermost '(...)': '" << spec); + abort(); + } + bool ret = getSequenceBoolValue(*sequence, default_); + return ret; + } + std::ostream& operator << (std::ostream& out, const Dump& dump) { out << "ViewPropertyEvaluator\n"; diff --git a/src/Viewer/ViewPropertyEvaluator.hxx b/src/Viewer/ViewPropertyEvaluator.hxx index 4779feba6..66be22d92 100644 --- a/src/Viewer/ViewPropertyEvaluator.hxx +++ b/src/Viewer/ViewPropertyEvaluator.hxx @@ -106,6 +106,9 @@ namespace ViewPropertyEvaluator { node, instead it always calls ->getDoubleValue(). */ double getDoubleValue(const char* spec, double default_=0); + + /* Similar to getDoubleValue(). */ + bool getBoolValue(const char* spec, bool default_=false); /* Outputs detailed information about all specs that have been seen.