bux API Reference
1.12.6
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.
Toggle main menu visibility
Loading...
Searching...
No Matches
include
bux
ImplGLR.h
Go to the documentation of this file.
1
#pragma once
2
6
7
#include "
ParserBase.h
"
// bux::FC_GetRelLexT<>, LexBase.h
8
#include <memory>
// std::shared_ptr<>
9
#include <vector>
// std::vector<>
10
11
namespace
bux
{
12
namespace
GLR
{
13
14
//
15
// Types
16
//
17
typedef
FC_GetRelLexT<const I_LexAttr,std::shared_ptr>
FC_GetRelLex
;
18
typedef
C_RetLvalT<const I_LexAttr,std::shared_ptr>
C_RetLval
;
19
20
//
21
// Function Templates
22
//
23
using
bux::index2value
;
24
25
template
<
class
T_Key,
class
T_Value,
class
T_ValueOrSize,
class
T_Traits>
26
std::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
57
template
<
class
T>
58
std::shared_ptr<C_LexDataT<T>>
dupLex
(
const
I_LexAttr
&lex)
59
{
60
return
std::make_shared<C_LexDataT<T>>(
unlex<T>
(lex));
61
}
62
63
template
<
class
T>
64
std::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
72
template
<
class
T>
73
std::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
ParserBase.h
bux::FC_GetRelLexT
Definition
ParserBase.h:24
bux::GLR
Definition
GLR.cpp:6
bux::GLR::FC_GetRelLex
FC_GetRelLexT< const I_LexAttr, std::shared_ptr > FC_GetRelLex
Definition
ImplGLR.h:17
bux::GLR::dupLex
std::shared_ptr< C_LexDataT< T > > dupLex(const I_LexAttr &lex)
Definition
ImplGLR.h:58
bux::GLR::tryDupLex
std::shared_ptr< C_LexDataT< T > > tryDupLex(const std::shared_ptr< const I_LexAttr > &lex)
Definition
ImplGLR.h:64
bux::GLR::index2values
std::vector< T_Value > index2values(U_K2V< T_Key, T_Value > k2v, T_ValueOrSize valOrSz, T_LexID key)
Definition
ImplGLR.h:26
bux::GLR::C_RetLval
C_RetLvalT< const I_LexAttr, std::shared_ptr > C_RetLval
Definition
ImplGLR.h:18
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
bux::unlex
auto & unlex(I_LexAttr &lex)
Definition
ParserBase.h:139
bux::tryUnlex
T_CoConst< T_Data, T_Lex > * tryUnlex(const C_Ptr< T_Lex > &lex)
Definition
ParserBase.h:163
bux::T_LexID
uint32_t T_LexID
Definition
LexBase.h:36
bux::index2value
T_Value index2value(U_K2V< T_Key, T_Value > k2v, T_ValueOrSize valOrSz, T_LexID key)
Definition
ParserBase.h:111
bux::C_KVPair
Definition
ParserBase.h:42
bux::C_LexInfoT
Definition
LexBase.h:54
bux::C_RetLvalT
Definition
LexBase.h:76
bux::I_LexAttr
Definition
LexBase.h:93
bux::U_K2V
Definition
ParserBase.h:49
bux::U_K2V::m_table
const C_KVPair< T_Key, T_Value > * m_table
Definition
ParserBase.h:50
bux::U_K2V::m_conv
int(*) m_conv(T_Key)
Definition
ParserBase.h:51
Generated by
1.18.0