Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : #ifndef OPENDDS_DCPS_ASTNODEWRAPPER_H 8 : #define OPENDDS_DCPS_ASTNODEWRAPPER_H 9 : 10 : #include "Definitions.h" 11 : #include "PoolAllocator.h" 12 : 13 : #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE 14 : 15 : #include "yard/yard_parser.hpp" 16 : #include <sstream> 17 : #include <stdexcept> 18 : 19 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 20 : 21 : namespace OpenDDS { 22 : namespace DCPS { 23 : 24 : typedef yard::TreeBuildingParser<char>::Node AstNode; 25 : 26 : /// called after parsing has failed, throws std::exception with details 27 0 : inline void reportErrors(yard::SimpleTextParser& parser, const char* input) 28 : { 29 0 : AstNode* prev = 0; 30 0 : for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter; 31 0 : iter = iter->GetSibling()) { 32 0 : prev = iter; 33 : } 34 0 : ptrdiff_t pos = prev ? prev->GetLastToken() - parser.Begin() : 0; 35 0 : std::ostringstream oss; 36 0 : oss << pos; 37 0 : throw std::runtime_error("Invalid expression [" + OPENDDS_STRING(input) 38 0 : + "] at character " + oss.str()); 39 0 : } 40 : 41 : 42 0 : inline OPENDDS_STRING toString(yard::TreeBuildingParser<char>::Node* iter) 43 : { 44 0 : return iter ? OPENDDS_STRING(iter->GetFirstToken(), iter->GetLastToken()) : ""; 45 : } 46 : 47 : 48 : /// keeps the details of yard out of the FilterEvaluator header file 49 : struct FilterEvaluator::AstNodeWrapper { 50 0 : AstNodeWrapper(AstNode* ptr) 51 0 : : ptr_(ptr) {} 52 0 : operator AstNode*() const { return ptr_; } 53 0 : AstNode* operator->() const { return ptr_; } 54 : AstNode* ptr_; 55 : }; 56 : 57 : } 58 : } 59 : 60 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 61 : 62 : #endif 63 : #endif