AstNodeWrapper.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 #ifndef OPENDDS_DCPS_ASTNODEWRAPPER_H
00008 #define OPENDDS_DCPS_ASTNODEWRAPPER_H
00009 
00010 #include "dds/DCPS/Definitions.h"
00011 #include "dds/DCPS/PoolAllocator.h"
00012 
00013 #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
00014 
00015 #include "yard/yard_parser.hpp"
00016 #include <sstream>
00017 #include <stdexcept>
00018 
00019 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 namespace OpenDDS {
00022 namespace DCPS {
00023 
00024 typedef yard::TreeBuildingParser<char>::Node AstNode;
00025 
00026 /// called after parsing has failed, throws std::exception with details
00027 inline void reportErrors(yard::SimpleTextParser& parser, const char* input)
00028 {
00029   AstNode* prev = 0;
00030   for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter;
00031       iter = iter->GetSibling()) {
00032     prev = iter;
00033   }
00034   ptrdiff_t pos = prev ? prev->GetLastToken() - parser.Begin() : 0;
00035   std::ostringstream oss;
00036   oss << pos;
00037   throw std::runtime_error("Invalid expression [" + OPENDDS_STRING(input)
00038     + "] at character " + oss.str());
00039 }
00040 
00041 
00042 inline OPENDDS_STRING toString(yard::TreeBuildingParser<char>::Node* iter)
00043 {
00044   return iter ? OPENDDS_STRING(iter->GetFirstToken(), iter->GetLastToken()) : "";
00045 }
00046 
00047 
00048 /// keeps the details of yard out of the FilterEvaluator header file
00049 struct FilterEvaluator::AstNodeWrapper {
00050   AstNodeWrapper(AstNode* ptr)
00051     : ptr_(ptr) {}
00052   operator AstNode*() const { return ptr_; }
00053   AstNode* operator->() const { return ptr_; }
00054   AstNode* ptr_;
00055 };
00056 
00057 }
00058 }
00059 
00060 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00061 
00062 #endif
00063 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1