OpenDDS  Snapshot(2023/04/28-20:55)
AstNodeWrapper.h
Go to the documentation of this file.
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 
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 inline void reportErrors(yard::SimpleTextParser& parser, const char* input)
28 {
29  AstNode* prev = 0;
30  for (AstNode* iter = parser.GetAstRoot()->GetFirstChild(); iter;
31  iter = iter->GetSibling()) {
32  prev = iter;
33  }
34  ptrdiff_t pos = prev ? prev->GetLastToken() - parser.Begin() : 0;
35  std::ostringstream oss;
36  oss << pos;
37  throw std::runtime_error("Invalid expression [" + OPENDDS_STRING(input)
38  + "] at character " + oss.str());
39 }
40 
41 
42 inline OPENDDS_STRING toString(yard::TreeBuildingParser<char>::Node* iter)
43 {
44  return iter ? OPENDDS_STRING(iter->GetFirstToken(), iter->GetLastToken()) : "";
45 }
46 
47 
48 /// keeps the details of yard out of the FilterEvaluator header file
50  AstNodeWrapper(AstNode* ptr)
51  : ptr_(ptr) {}
52  operator AstNode*() const { return ptr_; }
53  AstNode* operator->() const { return ptr_; }
54  AstNode* ptr_;
55 };
56 
57 }
58 }
59 
61 
62 #endif
63 #endif
keeps the details of yard out of the FilterEvaluator header file
yard::TreeBuildingParser< char >::Node AstNode
OPENDDS_STRING toString(yard::TreeBuildingParser< char >::Node *iter)
#define OPENDDS_STRING
void reportErrors(yard::SimpleTextParser &parser, const char *input)
called after parsing has failed, throws std::exception with details
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28