Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bool-expr-evaluator
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
playground
bool-expr-evaluator
Commits
b3d09d52
There was an error fetching the commit references. Please try again later.
Verified
Commit
b3d09d52
authored
5 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
remove dependency rlib
parent
6c1dc6b6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+1
-1
1 addition, 1 deletion
Makefile
parser.y
+1
-1
1 addition, 1 deletion
parser.y
rlib.min.hpp
+164
-0
164 additions, 0 deletions
rlib.min.hpp
with
166 additions
and
2 deletions
Makefile
+
1
−
1
View file @
b3d09d52
...
@@ -11,7 +11,7 @@ lexer.yy.cc: lexer.l parser.tab.h
...
@@ -11,7 +11,7 @@ lexer.yy.cc: lexer.l parser.tab.h
flex
-o
lexer.yy.cc lexer.l
flex
-o
lexer.yy.cc lexer.l
parser
:
generate
parser
:
generate
g++
-o
parser parser.tab.cc lexer.yy.cc
g++
-I
.
-o
parser parser.tab.cc lexer.yy.cc
clean
:
clean
:
rm
-f
parser parser.tab.cc lexer.yy.cc parser.tab.h
rm
-f
parser parser.tab.cc lexer.yy.cc parser.tab.h
This diff is collapsed.
Click to expand it.
parser.y
+
1
−
1
View file @
b3d09d52
%{
%{
#include <string>
#include <string>
#include <rlib
/stdio
.hpp>
#include <rlib
.min
.hpp>
#include <cassert>
#include <cassert>
#include <cstdlib>
#include <cstdlib>
...
...
This diff is collapsed.
Click to expand it.
rlib.min.hpp
0 → 100644
+
164
−
0
View file @
b3d09d52
/*
*
* string.hpp: string process utility.
* Recolic Keghart <root@recolic.net>
* MIT License
*
* Bensong Liu: This is my "nickname" and this lib is written by me. I want to use 'split string' function.
*
*/
#ifndef R_STRING_HPP
#define R_STRING_HPP
#include
<vector>
#include
<string>
#include
<stdexcept>
namespace
rlib
{
class
string
:
public
std
::
string
{
public:
using
std
::
string
::
string
;
string
()
:
std
::
string
()
{}
string
(
const
std
::
string
&
s
)
:
std
::
string
(
s
)
{}
string
(
std
::
string
&&
s
)
:
std
::
string
(
std
::
forward
<
std
::
string
>
(
s
))
{}
private
:
template
<
typename
T
>
struct
as_helper
{};
template
<
typename
T
>
T
as
(
as_helper
<
T
>
)
const
{
if
(
empty
())
return
T
();
return
T
(
*
this
);
}
std
::
string
as
(
as_helper
<
std
::
string
>
)
const
{
return
std
::
move
(
*
this
);
}
rlib
::
string
as
(
as_helper
<
rlib
::
string
>
)
const
{
return
std
::
move
(
*
this
);
}
char
as
(
as_helper
<
char
>
)
const
{
if
(
size
()
>
1
)
throw
std
::
invalid_argument
(
"Can not convert rlib::string to char: size() > 1."
);
return
size
()
==
0
?
'\0'
:
*
cbegin
();
}
unsigned
char
as
(
as_helper
<
unsigned
char
>
)
const
{
return
static_cast
<
unsigned
char
>
(
as
<
char
>
());
}
bool
as
(
as_helper
<
bool
>
)
const
{
if
(
*
this
==
"true"
)
{
return
true
;
}
else
if
(
*
this
==
"false"
)
{
return
false
;
}
// Nothing is slower than throw(); Just test more cases...
else
if
(
*
this
==
"1"
||
*
this
==
"True"
||
*
this
==
"TRUE"
)
{
return
true
;
}
else
if
(
*
this
==
"0"
||
*
this
==
"False"
||
*
this
==
"FALSE"
)
{
return
false
;
}
throw
std
::
invalid_argument
(
"Can not convert rlib::string to bool. Not matching any template."
);
}
#define RLIB_IMPL_GEN_AS_NUMERIC(type, std_conv) \
type as(as_helper<type>) const { \
if(empty()) return 0; \
return std::std_conv(*this); \
}
RLIB_IMPL_GEN_AS_NUMERIC
(
int
,
stoi
)
RLIB_IMPL_GEN_AS_NUMERIC
(
long
,
stol
)
RLIB_IMPL_GEN_AS_NUMERIC
(
unsigned
long
,
stoul
)
RLIB_IMPL_GEN_AS_NUMERIC
(
unsigned
long
long
,
stoull
)
RLIB_IMPL_GEN_AS_NUMERIC
(
long
long
,
stoll
)
RLIB_IMPL_GEN_AS_NUMERIC
(
float
,
stof
)
RLIB_IMPL_GEN_AS_NUMERIC
(
double
,
stod
)
RLIB_IMPL_GEN_AS_NUMERIC
(
long
double
,
stold
)
#define RLIB_IMPL_GEN_AS_ALIAS(new_type, old_type) \
new_type as(as_helper<new_type>) const { \
return static_cast<new_type>(as<old_type>()); \
}
RLIB_IMPL_GEN_AS_ALIAS
(
unsigned
int
,
unsigned
long
)
RLIB_IMPL_GEN_AS_ALIAS
(
unsigned
short
,
unsigned
long
)
//RLIB_IMPL_GEN_AS_ALIAS(uint8_t, unsigned long)
RLIB_IMPL_GEN_AS_ALIAS
(
short
,
int
)
//RLIB_IMPL_GEN_AS_ALIAS(int8_t, int)
public
:
template
<
typename
T
>
T
as
()
const
{
return
std
::
forward
<
T
>
(
as
(
as_helper
<
T
>
()));
}
template
<
typename
T
>
std
::
vector
<
T
>
split_as
(
const
char
&
divider
=
' '
)
const
{
const
string
&
toSplit
=
*
this
;
std
::
vector
<
T
>
buf
;
size_t
curr
=
0
,
prev
=
0
;
while
((
curr
=
toSplit
.
find
(
divider
,
curr
))
!=
std
::
string
::
npos
)
{
buf
.
push_back
(
string
(
toSplit
.
substr
(
prev
,
curr
-
prev
)).
as
<
T
>
());
++
curr
;
// skip divider
prev
=
curr
;
}
buf
.
push_back
(
string
(
toSplit
.
substr
(
prev
)).
as
<
T
>
());
return
std
::
move
(
buf
);
}
template
<
typename
T
>
std
::
vector
<
T
>
split_as
(
const
std
::
string
&
divider
)
const
{
const
string
&
toSplit
=
*
this
;
std
::
vector
<
T
>
buf
;
size_t
curr
=
0
,
prev
=
0
;
while
((
curr
=
toSplit
.
find
(
divider
,
curr
))
!=
std
::
string
::
npos
)
{
buf
.
push_back
(
string
(
toSplit
.
substr
(
prev
,
curr
-
prev
)).
as
<
T
>
());
curr
+=
divider
.
size
();
// skip divider
prev
=
curr
;
}
buf
.
push_back
(
string
(
toSplit
.
substr
(
prev
)).
as
<
T
>
());
return
std
::
move
(
buf
);
}
};
}
#endif
#include
<iostream>
#include
<string>
namespace
rlib
{
// This is my own hand-written library. I'm making it easy to use it directly.
inline
rlib
::
string
scanln
(
std
::
istream
&
is
=
std
::
cin
,
char
delimiter
=
'\n'
)
noexcept
{
std
::
string
line
;
std
::
getline
(
is
,
line
,
delimiter
);
return
(
line
);
// RVO
}
template
<
typename
PrintFinalT
>
void
print
(
PrintFinalT
reqArg
)
{
std
::
cout
<<
reqArg
;
}
template
<
typename
Required
,
typename
...
Optional
>
void
print
(
Required
reqArgs
,
Optional
...
optiArgs
)
{
std
::
cout
<<
reqArgs
<<
' '
;
print
(
optiArgs
...);
}
template
<
typename
...
Optional
>
void
println
(
Optional
...
optiArgs
)
{
print
(
optiArgs
...);
println
();
}
template
<
>
inline
void
println
()
{
//std::cout << rlib::endl;
std
::
cout
<<
std
::
endl
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment