Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
41001d1b
Unverified
Commit
41001d1b
authored
Jun 15, 2020
by
Rosen Penev
Committed by
GitHub
Jun 15, 2020
Browse files
manual algorithm conversions (#891)
Signed-off-by:
Rosen Penev
<
rosenp@gmail.com
>
parent
a808c1f4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
62 deletions
+54
-62
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+14
-21
include/yaml-cpp/node/detail/impl.h
include/yaml-cpp/node/detail/impl.h
+22
-16
src/convert.cpp
src/convert.cpp
+1
-5
src/emitterutils.cpp
src/emitterutils.cpp
+8
-15
src/node_data.cpp
src/node_data.cpp
+9
-5
No files found.
include/yaml-cpp/node/convert.h
View file @
41001d1b
...
@@ -225,9 +225,8 @@ template <typename K, typename V, typename C, typename A>
...
@@ -225,9 +225,8 @@ template <typename K, typename V, typename C, typename A>
struct
convert
<
std
::
map
<
K
,
V
,
C
,
A
>>
{
struct
convert
<
std
::
map
<
K
,
V
,
C
,
A
>>
{
static
Node
encode
(
const
std
::
map
<
K
,
V
,
C
,
A
>&
rhs
)
{
static
Node
encode
(
const
std
::
map
<
K
,
V
,
C
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Map
);
Node
node
(
NodeType
::
Map
);
for
(
typename
std
::
map
<
K
,
V
,
C
,
A
>::
const_iterator
it
=
rhs
.
begin
();
for
(
const
auto
&
it
:
rhs
)
it
!=
rhs
.
end
();
++
it
)
node
.
force_insert
(
it
.
first
,
it
.
second
);
node
.
force_insert
(
it
->
first
,
it
->
second
);
return
node
;
return
node
;
}
}
...
@@ -236,12 +235,12 @@ struct convert<std::map<K, V, C, A>> {
...
@@ -236,12 +235,12 @@ struct convert<std::map<K, V, C, A>> {
return
false
;
return
false
;
rhs
.
clear
();
rhs
.
clear
();
for
(
const
_itera
to
r
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
au
to
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
// workaround for GCC 3:
rhs
[
it
->
first
.
template
as
<
K
>()]
=
it
->
second
.
template
as
<
V
>();
rhs
[
it
.
first
.
template
as
<
K
>()]
=
it
.
second
.
template
as
<
V
>();
#else
#else
rhs
[
it
->
first
.
as
<
K
>
()]
=
it
->
second
.
as
<
V
>
();
rhs
[
it
.
first
.
as
<
K
>
()]
=
it
.
second
.
as
<
V
>
();
#endif
#endif
return
true
;
return
true
;
}
}
...
@@ -252,9 +251,7 @@ template <typename T, typename A>
...
@@ -252,9 +251,7 @@ template <typename T, typename A>
struct
convert
<
std
::
vector
<
T
,
A
>>
{
struct
convert
<
std
::
vector
<
T
,
A
>>
{
static
Node
encode
(
const
std
::
vector
<
T
,
A
>&
rhs
)
{
static
Node
encode
(
const
std
::
vector
<
T
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
Node
node
(
NodeType
::
Sequence
);
for
(
typename
std
::
vector
<
T
,
A
>::
const_iterator
it
=
rhs
.
begin
();
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
it
!=
rhs
.
end
();
++
it
)
node
.
push_back
(
*
it
);
return
node
;
return
node
;
}
}
...
@@ -263,12 +260,12 @@ struct convert<std::vector<T, A>> {
...
@@ -263,12 +260,12 @@ struct convert<std::vector<T, A>> {
return
false
;
return
false
;
rhs
.
clear
();
rhs
.
clear
();
for
(
const
_itera
to
r
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
au
to
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
// workaround for GCC 3:
rhs
.
push_back
(
it
->
template
as
<
T
>());
rhs
.
push_back
(
it
.
template
as
<
T
>());
#else
#else
rhs
.
push_back
(
it
->
as
<
T
>
());
rhs
.
push_back
(
it
.
as
<
T
>
());
#endif
#endif
return
true
;
return
true
;
}
}
...
@@ -279,9 +276,7 @@ template <typename T, typename A>
...
@@ -279,9 +276,7 @@ template <typename T, typename A>
struct
convert
<
std
::
list
<
T
,
A
>>
{
struct
convert
<
std
::
list
<
T
,
A
>>
{
static
Node
encode
(
const
std
::
list
<
T
,
A
>&
rhs
)
{
static
Node
encode
(
const
std
::
list
<
T
,
A
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
Node
node
(
NodeType
::
Sequence
);
for
(
typename
std
::
list
<
T
,
A
>::
const_iterator
it
=
rhs
.
begin
();
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
it
!=
rhs
.
end
();
++
it
)
node
.
push_back
(
*
it
);
return
node
;
return
node
;
}
}
...
@@ -290,12 +285,12 @@ struct convert<std::list<T,A>> {
...
@@ -290,12 +285,12 @@ struct convert<std::list<T,A>> {
return
false
;
return
false
;
rhs
.
clear
();
rhs
.
clear
();
for
(
const
_itera
to
r
it
=
node
.
begin
();
it
!=
node
.
end
();
++
it
)
for
(
const
au
to
&
it
:
node
)
#if defined(__GNUC__) && __GNUC__ < 4
#if defined(__GNUC__) && __GNUC__ < 4
// workaround for GCC 3:
// workaround for GCC 3:
rhs
.
push_back
(
it
->
template
as
<
T
>());
rhs
.
push_back
(
it
.
template
as
<
T
>());
#else
#else
rhs
.
push_back
(
it
->
as
<
T
>
());
rhs
.
push_back
(
it
.
as
<
T
>
());
#endif
#endif
return
true
;
return
true
;
}
}
...
@@ -306,9 +301,7 @@ template <typename T, std::size_t N>
...
@@ -306,9 +301,7 @@ template <typename T, std::size_t N>
struct
convert
<
std
::
array
<
T
,
N
>>
{
struct
convert
<
std
::
array
<
T
,
N
>>
{
static
Node
encode
(
const
std
::
array
<
T
,
N
>&
rhs
)
{
static
Node
encode
(
const
std
::
array
<
T
,
N
>&
rhs
)
{
Node
node
(
NodeType
::
Sequence
);
Node
node
(
NodeType
::
Sequence
);
for
(
const
auto
&
element
:
rhs
)
{
std
::
copy
(
rhs
.
begin
(),
rhs
.
end
(),
std
::
back_inserter
(
rhs
));
node
.
push_back
(
element
);
}
return
node
;
return
node
;
}
}
...
...
include/yaml-cpp/node/detail/impl.h
View file @
41001d1b
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/node/detail/node_data.h"
#include "yaml-cpp/node/detail/node_data.h"
#include <algorithm>
#include <type_traits>
#include <type_traits>
namespace
YAML
{
namespace
YAML
{
...
@@ -125,13 +127,11 @@ inline node* node_data::get(const Key& key,
...
@@ -125,13 +127,11 @@ inline node* node_data::get(const Key& key,
throw
BadSubscript
(
m_mark
,
key
);
throw
BadSubscript
(
m_mark
,
key
);
}
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
auto
it
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
if
(
it
->
first
->
equals
(
key
,
pMemory
))
{
return
m
.
first
->
equals
(
key
,
pMemory
);
return
it
->
second
;
});
}
}
return
nullptr
;
return
it
!=
m_map
.
end
()
?
it
->
second
:
nullptr
;
}
}
template
<
typename
Key
>
template
<
typename
Key
>
...
@@ -153,10 +153,12 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
...
@@ -153,10 +153,12 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) {
throw
BadSubscript
(
m_mark
,
key
);
throw
BadSubscript
(
m_mark
,
key
);
}
}
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
auto
it
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
if
(
it
->
first
->
equals
(
key
,
pMemory
))
{
return
m
.
first
->
equals
(
key
,
pMemory
);
return
*
it
->
second
;
});
}
if
(
it
!=
m_map
.
end
())
{
return
it
->
second
;
}
}
node
&
k
=
convert_to_node
(
key
,
pMemory
);
node
&
k
=
convert_to_node
(
key
,
pMemory
);
...
@@ -169,7 +171,9 @@ template <typename Key>
...
@@ -169,7 +171,9 @@ template <typename Key>
inline
bool
node_data
::
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
inline
bool
node_data
::
remove
(
const
Key
&
key
,
shared_memory_holder
pMemory
)
{
if
(
m_type
==
NodeType
::
Sequence
)
{
if
(
m_type
==
NodeType
::
Sequence
)
{
return
remove_idx
<
Key
>::
remove
(
m_sequence
,
key
,
m_seqSize
);
return
remove_idx
<
Key
>::
remove
(
m_sequence
,
key
,
m_seqSize
);
}
else
if
(
m_type
==
NodeType
::
Map
)
{
}
if
(
m_type
==
NodeType
::
Map
)
{
kv_pairs
::
iterator
it
=
m_undefinedPairs
.
begin
();
kv_pairs
::
iterator
it
=
m_undefinedPairs
.
begin
();
while
(
it
!=
m_undefinedPairs
.
end
())
{
while
(
it
!=
m_undefinedPairs
.
end
())
{
kv_pairs
::
iterator
jt
=
std
::
next
(
it
);
kv_pairs
::
iterator
jt
=
std
::
next
(
it
);
...
@@ -179,13 +183,15 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
...
@@ -179,13 +183,15 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
it
=
jt
;
it
=
jt
;
}
}
for
(
node_map
::
iterator
iter
=
m_map
.
begin
();
iter
!=
m_map
.
end
();
++
iter
)
{
auto
iter
=
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
const
kv_pair
m
)
{
if
(
iter
->
first
->
equals
(
key
,
pMemory
))
{
return
m
.
first
->
equals
(
key
,
pMemory
);
});
if
(
iter
!=
m_map
.
end
())
{
m_map
.
erase
(
iter
);
m_map
.
erase
(
iter
);
return
true
;
return
true
;
}
}
}
}
}
return
false
;
return
false
;
}
}
...
...
src/convert.cpp
View file @
41001d1b
...
@@ -16,11 +16,7 @@ std::string tolower(const std::string& str) {
...
@@ -16,11 +16,7 @@ std::string tolower(const std::string& str) {
template
<
typename
T
>
template
<
typename
T
>
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
bool
IsEntirely
(
const
std
::
string
&
str
,
T
func
)
{
for
(
char
ch
:
str
)
return
std
::
all_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
return
func
(
ch
);
});
if
(
!
func
(
ch
))
return
false
;
return
true
;
}
}
// IsFlexibleCase
// IsFlexibleCase
...
...
src/emitterutils.cpp
View file @
41001d1b
#include <algorithm>
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <sstream>
...
@@ -199,15 +200,10 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
...
@@ -199,15 +200,10 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
bool
IsValidSingleQuotedScalar
(
const
std
::
string
&
str
,
bool
escapeNonAscii
)
{
bool
IsValidSingleQuotedScalar
(
const
std
::
string
&
str
,
bool
escapeNonAscii
)
{
// TODO: check for non-printable characters?
// TODO: check for non-printable characters?
for
(
char
ch
:
str
)
{
return
std
::
none_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
||
return
false
;
(
ch
==
'\n'
);
}
});
if
(
ch
==
'\n'
)
{
return
false
;
}
}
return
true
;
}
}
bool
IsValidLiteralScalar
(
const
std
::
string
&
str
,
FlowType
::
value
flowType
,
bool
IsValidLiteralScalar
(
const
std
::
string
&
str
,
FlowType
::
value
flowType
,
...
@@ -217,12 +213,9 @@ bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
...
@@ -217,12 +213,9 @@ bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType,
}
}
// TODO: check for non-printable characters?
// TODO: check for non-printable characters?
for
(
char
ch
:
str
)
{
return
std
::
none_of
(
str
.
begin
(),
str
.
end
(),
[
=
](
char
ch
)
{
if
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)))
{
return
(
escapeNonAscii
&&
(
0x80
<=
static_cast
<
unsigned
char
>
(
ch
)));
return
false
;
});
}
}
return
true
;
}
}
void
WriteDoubleQuoteEscapeSequence
(
ostream_wrapper
&
out
,
int
codePoint
)
{
void
WriteDoubleQuoteEscapeSequence
(
ostream_wrapper
&
out
,
int
codePoint
)
{
...
...
src/node_data.cpp
View file @
41001d1b
...
@@ -252,12 +252,16 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
...
@@ -252,12 +252,16 @@ bool node_data::remove(node& key, shared_memory_holder /* pMemory */) {
it
=
jt
;
it
=
jt
;
}
}
for
(
node_map
::
iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
auto
it
=
if
(
it
->
first
->
is
(
key
))
{
std
::
find_if
(
m_map
.
begin
(),
m_map
.
end
(),
[
&
](
std
::
pair
<
YAML
::
detail
::
node
*
,
YAML
::
detail
::
node
*>
j
)
{
return
(
j
.
first
->
is
(
key
));
});
if
(
it
!=
m_map
.
end
())
{
m_map
.
erase
(
it
);
m_map
.
erase
(
it
);
return
true
;
return
true
;
}
}
}
return
false
;
return
false
;
}
}
...
...
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