bux API Reference 1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
ImplGLR.h
Go to the documentation of this file.
1#pragma once
2
7#include "ParserBase.h" // bux::FC_GetRelLexT<>, LexBase.h
8#include <memory> // std::shared_ptr<>
9#include <vector> // std::vector<>
10
11namespace bux {
12namespace GLR {
13
14//
15// Types
16//
19
20//
21// Function Templates
22//
24
25template<class T_Key, class T_Value, class T_ValueOrSize, class T_Traits>
26std::vector<T_Value> index2values(U_K2V<T_Key,T_Value> k2v, T_ValueOrSize valOrSz, T_LexID key)
27{
28 // Constraints
29 static_assert(std::numeric_limits<T_ValueOrSize>::is_signed && sizeof(T_Value) <= sizeof(T_ValueOrSize),
30 "T_Value/T_ValueOrSize criteria");
31
32 std::vector<T_Value> ret;
33 if (valOrSz < 0)
34 // (-valOrSz) is size of index array
35 {
36 const auto end = k2v.m_table - valOrSz;
37 auto found = std::lower_bound(k2v.m_table, end, key,
38 [](C_KVPair<T_Key,T_Value> a, T_LexID b)->bool {
39 return a.m_key < b;
40 });
41 while (found < end && found->m_key == key)
42 {
43 ret.emplace_back(found->m_value);
44 ++found;
45 }
46 }
47 else
48 // valOrSz is THE value
49 {
50 const auto ind = k2v.m_conv(T_Key(key));
51 if (ind >= 0)
52 ret.emplace_back(T_Traits::map(valOrSz, ind));
53 }
54 return ret;
55}
56
57template<class T>
58std::shared_ptr<C_LexDataT<T>> dupLex(const I_LexAttr &lex)
59{
60 return std::make_shared<C_LexDataT<T>>(unlex<T>(lex));
61}
62
63template<class T>
64std::shared_ptr<C_LexDataT<T>> tryDupLex(const std::shared_ptr<const I_LexAttr> &lex)
65{
66 if (auto t = tryUnlex<T>(lex))
67 return std::make_shared<C_LexDataT<T>>(*t);
68
69 return {};
70}
71
72template<class T>
73std::shared_ptr<C_LexDataT<T>> tryDupLex(const C_LexInfoT<const I_LexAttr,std::shared_ptr> &lex)
74{
75 if (auto t = tryUnlex<T>(lex))
76 return std::make_shared<C_LexDataT<T>>(*t);
77
78 return {};
79}
80
81} // namespace GLR
82} //namespace bux
FC_GetRelLexT< const I_LexAttr, std::shared_ptr > FC_GetRelLex
Definition ImplGLR.h:17
std::shared_ptr< C_LexDataT< T > > dupLex(const I_LexAttr &lex)
Definition ImplGLR.h:58
std::shared_ptr< C_LexDataT< T > > tryDupLex(const std::shared_ptr< const I_LexAttr > &lex)
Definition ImplGLR.h:64
std::vector< T_Value > index2values(U_K2V< T_Key, T_Value > k2v, T_ValueOrSize valOrSz, T_LexID key)
Definition ImplGLR.h:26
C_RetLvalT< const I_LexAttr, std::shared_ptr > C_RetLval
Definition ImplGLR.h:18
THE common namespace of bux library.
Definition AtomiX.cpp:3
auto & unlex(I_LexAttr &lex)
Definition ParserBase.h:139
T_CoConst< T_Data, T_Lex > * tryUnlex(const C_Ptr< T_Lex > &lex)
Definition ParserBase.h:163
uint32_t T_LexID
Definition LexBase.h:35
T_Value index2value(U_K2V< T_Key, T_Value > k2v, T_ValueOrSize valOrSz, T_LexID key)
Definition ParserBase.h:111
const C_KVPair< T_Key, T_Value > * m_table
Definition ParserBase.h:50
int(* m_conv)(T_Key)
Definition ParserBase.h:51