3 #ifndef pfp_cpCommandParserBase_h_included
4 #define pfp_cpCommandParserBase_h_included
45 template <
typename Tp_>
50 struct TagOf<DeleteCommand *>
52 static Tag__
const tag = Tag__::DELETE_COMMAND;
56 struct TagOf<ModifyCommand *>
58 static Tag__
const tag = Tag__::MODIFY_COMMAND;
62 struct TagOf<InsertCommand *>
64 static Tag__
const tag = Tag__::INSERT_COMMAND;
70 static Tag__
const tag = Tag__::BYTES;
74 struct TagOf<ExactKey *>
76 static Tag__
const tag = Tag__::EXACT_KEY_PARAM;
80 struct TagOf<unsigned long long>
82 static Tag__
const tag = Tag__::INTEGER;
86 struct TagOf<
std::string>
88 static Tag__
const tag = Tag__::STRING;
92 struct TagOf<Action *>
94 static Tag__
const tag = Tag__::ACTION_SPEC;
98 struct TagOf<LpmKey *>
100 static Tag__
const tag = Tag__::LPM_KEY_PARAM;
104 struct TagOf<MatchKey *>
106 static Tag__
const tag = Tag__::MATCH_KEY;
110 struct TagOf<TernaryKey *>
112 static Tag__
const tag = Tag__::TERNARY_KEY_PARAM;
116 struct TagOf<MatchKeyContainer *>
118 static Tag__
const tag = Tag__::MATCH_KEYS;
122 struct TagOf<Command *>
124 static Tag__
const tag = Tag__::COMMAND;
128 struct TypeOf<Tag__::DELETE_COMMAND>
130 typedef DeleteCommand * type;
134 struct TypeOf<Tag__::MODIFY_COMMAND>
136 typedef ModifyCommand * type;
140 struct TypeOf<Tag__::INSERT_COMMAND>
142 typedef InsertCommand * type;
146 struct TypeOf<Tag__::BYTES>
152 struct TypeOf<Tag__::EXACT_KEY_PARAM>
154 typedef ExactKey * type;
158 struct TypeOf<Tag__::INTEGER>
160 typedef unsigned long long type;
164 struct TypeOf<Tag__::STRING>
166 typedef std::string type;
170 struct TypeOf<Tag__::ACTION_SPEC>
172 typedef Action * type;
176 struct TypeOf<Tag__::LPM_KEY_PARAM>
178 typedef LpmKey * type;
182 struct TypeOf<Tag__::MATCH_KEY>
184 typedef MatchKey * type;
188 struct TypeOf<Tag__::TERNARY_KEY_PARAM>
190 typedef TernaryKey * type;
194 struct TypeOf<Tag__::MATCH_KEYS>
196 typedef MatchKeyContainer * type;
200 struct TypeOf<Tag__::COMMAND>
202 typedef Command * type;
219 Base(Base
const &other) =
delete;
224 typename TypeOf<tg_>::type &
get();
230 class Semantic:
public Base
232 typedef typename TypeOf<tg_>::type DataType;
240 Semantic(DataType
const &data);
241 Semantic(DataType &&tmp);
254 struct SType:
public std::shared_ptr<Base>
256 template <
typename Tp_>
257 SType &operator=(Tp_ &&value);
265 typename TypeOf<tg_>::type &
get();
270 typename TypeOf<tg_>::type &data();
275 class CommandParserBase
295 typedef Meta__::SType STYPE__;
300 std::vector<size_t> d_stateStack__;
301 std::vector<STYPE__> d_valueStack__;
311 DEFAULT_RECOVERY_MODE__,
316 size_t d_requiredTokens__;
317 size_t d_acceptedTokens__;
332 void pop__(
size_t count = 1);
333 void push__(
size_t nextState);
335 void pushToken__(
int token);
336 void reduce__(PI__
const &productionInfo);
337 void errorVerbose__();
338 size_t top__()
const;
341 void setDebug(
bool mode);
344 inline bool CommandParserBase::debug()
const
349 inline void CommandParserBase::setDebug(
bool mode)
354 inline void CommandParserBase::ABORT()
const
359 inline void CommandParserBase::ACCEPT()
const
361 throw PARSE_ACCEPT__;
364 inline void CommandParserBase::ERROR()
const
366 throw UNEXPECTED_TOKEN__;
373 inline Base::Base(Tag__ tag)
378 inline Tag__ Base::tag()
const
384 inline Semantic<tg_>::Semantic()
387 d_data(typename TypeOf<tg_>::type())
391 inline Semantic<tg_>::Semantic(
typename TypeOf<tg_>::type
const &data)
398 inline Semantic<tg_>::Semantic(
typename TypeOf<tg_>::type &&tmp)
401 d_data(
std::move(tmp))
405 inline typename TypeOf<tg_>::type &Semantic<tg_>::data()
411 inline typename TypeOf<tg_>::type &Base::get()
413 return static_cast<Semantic<tg_> *
>(
this)->data();
416 inline Tag__ SType::tag()
const
418 return std::shared_ptr<Base>::get()->tag();
422 inline typename TypeOf<tg_>::type &SType::get()
426 if (std::shared_ptr<Base>::get() == 0 || tag() != tg_)
427 reset(
new Semantic<tg_>());
429 return std::shared_ptr<Base>::get()->get<tg_>();
433 inline typename TypeOf<tg_>::type &SType::data()
435 return std::shared_ptr<Base>::get()->get<tg_>();
438 template <
bool,
typename Tp_>
441 template <
typename Tp_>
442 struct Assign<true, Tp_>
444 static SType &assign(SType *lhs, Tp_ &&tp);
447 template <
typename Tp_>
448 struct Assign<false, Tp_>
450 static SType &assign(SType *lhs, Tp_
const &tp);
454 struct Assign<false, SType>
456 static SType &assign(SType *lhs, SType
const &tp);
459 template <
typename Tp_>
460 inline SType &Assign<true, Tp_>::assign(SType *lhs, Tp_ &&tp)
462 lhs->reset(
new Semantic<TagOf<Tp_>::tag>(std::move(tp)));
466 template <
typename Tp_>
467 inline SType &Assign<false, Tp_>::assign(SType *lhs, Tp_
const &tp)
469 lhs->reset(
new Semantic<TagOf<Tp_>::tag>(tp));
473 inline SType &Assign<false, SType>::assign(SType *lhs, SType
const &tp)
475 return lhs->operator=(tp);
478 template <
typename Tp_>
479 inline SType &SType::operator=(Tp_ &&rhs)
482 std::is_rvalue_reference<Tp_ &&>::value,
483 typename std::remove_reference<Tp_>::type
484 >::assign(
this, std::forward<Tp_>(rhs));
491 #define CommandParser CommandParserBase
Definition: json.hpp:8681
Definition: CommandParser.h:50