Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
90
Issues
90
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
03714c6c
Commit
03714c6c
authored
Mar 17, 2018
by
louiz’
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Use std::optional<bool> instead of OptionalBool"
This reverts commit
ba879a88
.
parent
d0e3c71b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
42 deletions
+59
-42
src/database/database.hpp
src/database/database.hpp
+1
-1
src/database/query.cpp
src/database/query.cpp
+6
-6
src/database/query.hpp
src/database/query.hpp
+2
-2
src/database/select_query.hpp
src/database/select_query.hpp
+5
-4
src/utils/optional_bool.cpp
src/utils/optional_bool.cpp
+2
-2
src/utils/optional_bool.hpp
src/utils/optional_bool.hpp
+32
-16
src/xmpp/biboumi_adhoc_commands.cpp
src/xmpp/biboumi_adhoc_commands.cpp
+7
-7
tests/database.cpp
tests/database.cpp
+4
-4
No files found.
src/database/database.hpp
View file @
03714c6c
...
...
@@ -69,7 +69,7 @@ class Database
struct
RecordHistory
:
Column
<
bool
>
{
static
constexpr
auto
name
=
"recordhistory_"
;
RecordHistory
()
:
Column
<
bool
>
(
true
)
{}};
struct
RecordHistoryOptional
:
Column
<
std
::
optional
<
bool
>
>
{
static
constexpr
auto
name
=
"recordhistory_"
;
};
struct
RecordHistoryOptional
:
Column
<
OptionalBool
>
{
static
constexpr
auto
name
=
"recordhistory_"
;
};
struct
VerifyCert
:
Column
<
bool
>
{
static
constexpr
auto
name
=
"verifycert_"
;
VerifyCert
()
:
Column
<
bool
>
(
true
)
{}
};
...
...
src/database/query.cpp
View file @
03714c6c
...
...
@@ -11,11 +11,11 @@ void actual_bind(Statement& statement, const std::int64_t& value, int index)
statement
.
bind_int64
(
index
,
value
);
}
void
actual_bind
(
Statement
&
statement
,
const
std
::
optional
<
bool
>
&
value
,
int
index
)
void
actual_bind
(
Statement
&
statement
,
const
OptionalBool
&
value
,
int
index
)
{
if
(
!
value
)
if
(
!
value
.
is_set
)
statement
.
bind_int64
(
index
,
0
);
else
if
(
*
value
)
else
if
(
value
.
value
)
statement
.
bind_int64
(
index
,
1
);
else
statement
.
bind_int64
(
index
,
-
1
);
...
...
@@ -26,11 +26,11 @@ void actual_add_param(Query& query, const std::string& val)
query
.
params
.
push_back
(
val
);
}
void
actual_add_param
(
Query
&
query
,
const
std
::
optional
<
bool
>
&
val
)
void
actual_add_param
(
Query
&
query
,
const
OptionalBool
&
val
)
{
if
(
!
val
)
if
(
!
val
.
is_set
)
query
.
params
.
push_back
(
"0"
);
else
if
(
*
val
)
else
if
(
val
.
value
)
query
.
params
.
push_back
(
"1"
);
else
query
.
params
.
push_back
(
"-1"
);
...
...
src/database/query.hpp
View file @
03714c6c
...
...
@@ -18,7 +18,7 @@ void actual_bind(Statement& statement, const T& value, int index)
{
actual_bind
(
statement
,
static_cast
<
std
::
int64_t
>
(
value
),
index
);
}
void
actual_bind
(
Statement
&
statement
,
const
std
::
optional
<
bool
>
&
value
,
int
index
);
void
actual_bind
(
Statement
&
statement
,
const
OptionalBool
&
value
,
int
index
);
#ifdef DEBUG_SQL_QUERIES
#include <utils/scopetimer.hpp>
...
...
@@ -71,6 +71,7 @@ void actual_add_param(Query& query, const T& val)
}
void
actual_add_param
(
Query
&
query
,
const
std
::
string
&
val
);
void
actual_add_param
(
Query
&
query
,
const
OptionalBool
&
val
);
template
<
typename
T
>
typename
std
::
enable_if
<!
std
::
is_integral
<
T
>::
value
,
Query
&>::
type
...
...
@@ -79,7 +80,6 @@ operator<<(Query& query, const T&)
query
.
body
+=
T
::
name
;
return
query
;
}
void
actual_add_param
(
Query
&
query
,
const
std
::
optional
<
bool
>&
val
);
Query
&
operator
<<
(
Query
&
query
,
const
char
*
str
);
Query
&
operator
<<
(
Query
&
query
,
const
std
::
string
&
str
);
...
...
src/database/select_query.hpp
View file @
03714c6c
...
...
@@ -29,15 +29,16 @@ extract_row_value(Statement& statement, const int i)
}
template
<
typename
T
>
typename
std
::
enable_if
<
std
::
is_same
<
std
::
optional
<
bool
>
,
T
>::
value
,
T
>::
type
typename
std
::
enable_if
<
std
::
is_same
<
OptionalBool
,
T
>::
value
,
T
>::
type
extract_row_value
(
Statement
&
statement
,
const
int
i
)
{
const
auto
integer
=
statement
.
get_column_int
(
i
);
OptionalBool
result
;
if
(
integer
>
0
)
re
turn
true
;
re
sult
.
set_value
(
true
)
;
else
if
(
integer
<
0
)
re
turn
false
;
return
std
::
nullop
t
;
re
sult
.
set_value
(
false
)
;
return
resul
t
;
}
template
<
std
::
size_t
N
=
0
,
typename
...
T
>
...
...
src/utils/optional_bool.cpp
View file @
03714c6c
#include <utils/optional_bool.hpp>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
std
::
optional
<
bool
>
&
o
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
OptionalBool
&
o
)
{
os
<<
std
::
to_string
(
o
);
os
<<
o
.
to_string
(
);
return
os
;
}
src/utils/optional_bool.hpp
View file @
03714c6c
#pragma once
#include <optional>
#include <string>
namespace
std
{
inline
std
::
string
to_string
(
const
std
::
optional
<
bool
>
b
)
struct
OptionalBool
{
if
(
!
b
)
return
"unset"
;
else
if
(
*
b
)
return
"true"
;
else
return
"false"
;
}
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
std
::
optional
<
bool
>&
o
);
OptionalBool
()
=
default
;
OptionalBool
(
bool
value
)
:
is_set
(
true
),
value
(
value
)
{}
void
set_value
(
bool
value
)
{
this
->
is_set
=
true
;
this
->
value
=
value
;
}
void
unset
()
{
this
->
is_set
=
false
;
}
std
::
string
to_string
()
const
{
if
(
this
->
is_set
==
false
)
return
"unset"
;
else
if
(
this
->
value
)
return
"true"
;
else
return
"false"
;
}
bool
is_set
{
false
};
bool
value
{
false
};
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
OptionalBool
&
o
);
src/xmpp/biboumi_adhoc_commands.cpp
View file @
03714c6c
...
...
@@ -493,7 +493,7 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester,
{
// Value selected by default
XmlSubNode
value
(
record_history
,
"value"
);
value
.
set_inner
(
std
::
to_string
(
options
.
col
<
Database
::
RecordHistoryOptional
>
()
));
value
.
set_inner
(
options
.
col
<
Database
::
RecordHistoryOptional
>
().
to_string
(
));
}
// All three possible values
for
(
const
auto
&
val
:
{
"unset"
,
"true"
,
"false"
})
...
...
@@ -594,19 +594,19 @@ bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const
else
if
(
field
->
get_tag
(
"var"
)
==
"record_history"
&&
value
&&
!
value
->
get_inner
().
empty
())
{
std
::
optional
<
bool
>
&
database_value
=
options
.
col
<
Database
::
RecordHistoryOptional
>
();
OptionalBool
&
database_value
=
options
.
col
<
Database
::
RecordHistoryOptional
>
();
if
(
value
->
get_inner
()
==
"true"
)
database_value
=
true
;
database_value
.
set_value
(
true
)
;
else
if
(
value
->
get_inner
()
==
"false"
)
database_value
=
false
;
database_value
.
set_value
(
false
)
;
else
database_value
.
re
set
();
database_value
.
un
set
();
auto
&
biboumi_component
=
dynamic_cast
<
BiboumiComponent
&>
(
xmpp_component
);
Bridge
*
bridge
=
biboumi_component
.
find_user_bridge
(
requester
.
bare
());
if
(
bridge
)
{
if
(
database_value
)
bridge
->
set_record_history
(
*
database_
value
);
if
(
database_value
.
is_set
)
bridge
->
set_record_history
(
database_value
.
value
);
else
{
// It is unset, we need to fetch the Global option, to
// know if it’s enabled or not
...
...
tests/database.cpp
View file @
03714c6c
...
...
@@ -56,13 +56,13 @@ TEST_CASE("Database")
CHECK
(
o
.
col
<
Database
::
EncodingIn
>
()
==
""
);
o
.
col
<
Database
::
EncodingIn
>
()
=
"ISO-8859-1"
;
CHECK
(
!
o
.
col
<
Database
::
RecordHistoryOptional
>
()
);
o
.
col
<
Database
::
RecordHistoryOptional
>
()
=
false
;
CHECK
(
o
.
col
<
Database
::
RecordHistoryOptional
>
().
is_set
==
false
);
o
.
col
<
Database
::
RecordHistoryOptional
>
()
.
set_value
(
false
)
;
o
.
save
(
Database
::
db
);
auto
b
=
Database
::
get_irc_channel_options
(
"zouzou@example.com"
,
"irc.example.com"
,
"#foo"
);
CHECK
(
o
.
col
<
Database
::
EncodingIn
>
()
==
"ISO-8859-1"
);
CHECK
(
o
.
col
<
Database
::
RecordHistoryOptional
>
());
CHECK
(
*
o
.
col
<
Database
::
RecordHistoryOptional
>
()
==
false
);
CHECK
(
o
.
col
<
Database
::
RecordHistoryOptional
>
()
.
is_set
==
true
);
CHECK
(
o
.
col
<
Database
::
RecordHistoryOptional
>
().
value
==
false
);
}
SECTION
(
"Channel options with server default"
)
...
...
louiz’
@louiz
mentioned in commit
f8a1048f
·
Mar 17, 2018
mentioned in commit
f8a1048f
mentioned in commit f8a1048ffeec6322c1e64a0eda7636a977669898
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment