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
a78069a6
Commit
a78069a6
authored
May 25, 2012
by
Jesse Beder
Browse files
Merged ostreams for the emitter change from the core
parents
4116d89f
bc3f72b5
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
174 additions
and
154 deletions
+174
-154
include/yaml-cpp/emitter.h
include/yaml-cpp/emitter.h
+4
-3
include/yaml-cpp/ostream.h
include/yaml-cpp/ostream.h
+0
-43
include/yaml-cpp/ostream_wrapper.h
include/yaml-cpp/ostream_wrapper.h
+69
-0
src/emitter.cpp
src/emitter.cpp
+4
-0
src/emitterutils.cpp
src/emitterutils.cpp
+24
-26
src/emitterutils.h
src/emitterutils.h
+11
-11
src/indentation.h
src/indentation.h
+3
-3
src/ostream.cpp
src/ostream.cpp
+0
-64
src/ostream_wrapper.cpp
src/ostream_wrapper.cpp
+56
-0
util/sandbox.cpp
util/sandbox.cpp
+3
-4
No files found.
include/yaml-cpp/emitter.h
View file @
a78069a6
...
...
@@ -10,9 +10,9 @@
#include "yaml-cpp/binary.h"
#include "yaml-cpp/emitterdef.h"
#include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/null.h"
#include "yaml-cpp/ostream_wrapper.h"
#include <memory>
#include <string>
#include <sstream>
...
...
@@ -25,6 +25,7 @@ namespace YAML
{
public:
Emitter
();
explicit
Emitter
(
std
::
ostream
&
stream
);
~
Emitter
();
// output
...
...
@@ -114,8 +115,8 @@ namespace YAML
bool
CanEmitNewline
()
const
;
private:
o
st
ream
m_stream
;
st
d
::
auto_ptr
<
EmitterState
>
m_pState
;
st
d
::
auto_ptr
<
EmitterState
>
m_pState
;
o
st
ream_wrapper
m_stream
;
};
template
<
typename
T
>
...
...
include/yaml-cpp/ostream.h
deleted
100644 → 0
View file @
4116d89f
#ifndef OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace
YAML
{
class
ostream
{
public:
ostream
();
~
ostream
();
void
reserve
(
unsigned
size
);
void
put
(
char
ch
);
void
set_comment
()
{
m_comment
=
true
;
}
const
char
*
str
()
const
{
return
m_buffer
;
}
unsigned
row
()
const
{
return
m_row
;
}
unsigned
col
()
const
{
return
m_col
;
}
unsigned
pos
()
const
{
return
m_pos
;
}
bool
comment
()
const
{
return
m_comment
;
}
private:
char
*
m_buffer
;
unsigned
m_pos
;
unsigned
m_size
;
unsigned
m_row
,
m_col
;
bool
m_comment
;
};
ostream
&
operator
<<
(
ostream
&
out
,
const
char
*
str
);
ostream
&
operator
<<
(
ostream
&
out
,
const
std
::
string
&
str
);
ostream
&
operator
<<
(
ostream
&
out
,
char
ch
);
}
#endif // OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
include/yaml-cpp/ostream_wrapper.h
0 → 100644
View file @
a78069a6
#ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <vector>
namespace
YAML
{
class
ostream_wrapper
{
public:
ostream_wrapper
();
explicit
ostream_wrapper
(
std
::
ostream
&
stream
);
~
ostream_wrapper
();
void
write
(
const
std
::
string
&
str
);
void
write
(
const
char
*
str
,
std
::
size_t
size
);
void
set_comment
()
{
m_comment
=
true
;
}
const
char
*
str
()
const
{
if
(
m_pStream
)
{
return
0
;
}
else
{
m_buffer
[
m_pos
]
=
'\0'
;
return
&
m_buffer
[
0
];
}
}
std
::
size_t
row
()
const
{
return
m_row
;
}
std
::
size_t
col
()
const
{
return
m_col
;
}
std
::
size_t
pos
()
const
{
return
m_pos
;
}
bool
comment
()
const
{
return
m_comment
;
}
private:
void
update_pos
(
char
ch
);
private:
mutable
std
::
vector
<
char
>
m_buffer
;
std
::
ostream
*
m_pStream
;
std
::
size_t
m_pos
;
std
::
size_t
m_row
,
m_col
;
bool
m_comment
;
};
template
<
std
::
size_t
N
>
inline
ostream_wrapper
&
operator
<<
(
ostream_wrapper
&
stream
,
const
char
(
&
str
)[
N
])
{
stream
.
write
(
str
,
N
-
1
);
return
stream
;
}
inline
ostream_wrapper
&
operator
<<
(
ostream_wrapper
&
stream
,
const
std
::
string
&
str
)
{
stream
.
write
(
str
);
return
stream
;
}
inline
ostream_wrapper
&
operator
<<
(
ostream_wrapper
&
stream
,
char
ch
)
{
stream
.
write
(
&
ch
,
1
);
return
stream
;
}
}
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/emitter.cpp
View file @
a78069a6
...
...
@@ -11,6 +11,10 @@ namespace YAML
{
}
Emitter
::
Emitter
(
std
::
ostream
&
stream
)
:
m_pState
(
new
EmitterState
),
m_stream
(
stream
)
{
}
Emitter
::~
Emitter
()
{
}
...
...
src/emitterutils.cpp
View file @
a78069a6
...
...
@@ -107,7 +107,7 @@ namespace YAML
return
true
;
}
void
WriteCodePoint
(
ostream
&
out
,
int
codePoint
)
{
void
WriteCodePoint
(
ostream
_wrapper
&
out
,
int
codePoint
)
{
if
(
codePoint
<
0
||
codePoint
>
0x10FFFF
)
{
codePoint
=
REPLACEMENT_CHARACTER
;
}
...
...
@@ -185,30 +185,28 @@ namespace YAML
return
true
;
}
void
WriteDoubleQuoteEscapeSequence
(
ostream
&
out
,
int
codePoint
)
{
void
WriteDoubleQuoteEscapeSequence
(
ostream
_wrapper
&
out
,
int
codePoint
)
{
static
const
char
hexDigits
[]
=
"0123456789abcdef"
;
char
escSeq
[]
=
"
\\
U00000000
"
;
out
<<
"
\\
"
;
int
digits
=
8
;
if
(
codePoint
<
0xFF
)
{
escSeq
[
1
]
=
'x'
;
if
(
codePoint
<
0xFF
)
{
out
<<
"x"
;
digits
=
2
;
}
else
if
(
codePoint
<
0xFFFF
)
{
escSeq
[
1
]
=
'u'
;
}
else
if
(
codePoint
<
0xFFFF
)
{
out
<<
"u"
;
digits
=
4
;
}
}
else
{
out
<<
"U"
;
digits
=
8
;
}
// Write digits into the escape sequence
int
i
=
2
;
for
(;
digits
>
0
;
--
digits
,
++
i
)
{
escSeq
[
i
]
=
hexDigits
[(
codePoint
>>
(
4
*
(
digits
-
1
)))
&
0xF
];
}
escSeq
[
i
]
=
0
;
// terminate with NUL character
out
<<
escSeq
;
for
(;
digits
>
0
;
--
digits
)
out
<<
hexDigits
[(
codePoint
>>
(
4
*
(
digits
-
1
)))
&
0xF
];
}
bool
WriteAliasName
(
ostream
&
out
,
const
std
::
string
&
str
)
{
bool
WriteAliasName
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
)
{
int
codePoint
;
for
(
std
::
string
::
const_iterator
i
=
str
.
begin
();
GetNextCodePointAndAdvance
(
codePoint
,
i
,
str
.
end
());
...
...
@@ -247,7 +245,7 @@ namespace YAML
return
StringFormat
::
DoubleQuoted
;
}
bool
WriteSingleQuotedString
(
ostream
&
out
,
const
std
::
string
&
str
)
bool
WriteSingleQuotedString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
)
{
out
<<
"'"
;
int
codePoint
;
...
...
@@ -267,7 +265,7 @@ namespace YAML
return
true
;
}
bool
WriteDoubleQuotedString
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
escapeNonAscii
)
bool
WriteDoubleQuotedString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
bool
escapeNonAscii
)
{
out
<<
"
\"
"
;
int
codePoint
;
...
...
@@ -297,7 +295,7 @@ namespace YAML
return
true
;
}
bool
WriteLiteralString
(
ostream
&
out
,
const
std
::
string
&
str
,
int
indent
)
bool
WriteLiteralString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
int
indent
)
{
out
<<
"|
\n
"
;
out
<<
IndentTo
(
indent
);
...
...
@@ -314,7 +312,7 @@ namespace YAML
return
true
;
}
bool
WriteChar
(
ostream
&
out
,
char
ch
)
bool
WriteChar
(
ostream
_wrapper
&
out
,
char
ch
)
{
if
((
'a'
<=
ch
&&
ch
<=
'z'
)
||
(
'A'
<=
ch
&&
ch
<=
'Z'
))
out
<<
ch
;
...
...
@@ -334,7 +332,7 @@ namespace YAML
return
true
;
}
bool
WriteComment
(
ostream
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
)
bool
WriteComment
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
)
{
const
unsigned
curIndent
=
out
.
col
();
out
<<
"#"
<<
Indentation
(
postCommentIndent
);
...
...
@@ -354,19 +352,19 @@ namespace YAML
return
true
;
}
bool
WriteAlias
(
ostream
&
out
,
const
std
::
string
&
str
)
bool
WriteAlias
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
)
{
out
<<
"*"
;
return
WriteAliasName
(
out
,
str
);
}
bool
WriteAnchor
(
ostream
&
out
,
const
std
::
string
&
str
)
bool
WriteAnchor
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
)
{
out
<<
"&"
;
return
WriteAliasName
(
out
,
str
);
}
bool
WriteTag
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
verbatim
)
bool
WriteTag
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
bool
verbatim
)
{
out
<<
(
verbatim
?
"!<"
:
"!"
);
StringCharSource
buffer
(
str
.
c_str
(),
str
.
size
());
...
...
@@ -386,7 +384,7 @@ namespace YAML
return
true
;
}
bool
WriteTagWithPrefix
(
ostream
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
)
bool
WriteTagWithPrefix
(
ostream
_wrapper
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
)
{
out
<<
"!"
;
StringCharSource
prefixBuffer
(
prefix
.
c_str
(),
prefix
.
size
());
...
...
@@ -416,7 +414,7 @@ namespace YAML
return
true
;
}
bool
WriteBinary
(
ostream
&
out
,
const
Binary
&
binary
)
bool
WriteBinary
(
ostream
_wrapper
&
out
,
const
Binary
&
binary
)
{
WriteDoubleQuotedString
(
out
,
EncodeBase64
(
binary
.
data
(),
binary
.
size
()),
false
);
return
true
;
...
...
src/emitterutils.h
View file @
a78069a6
...
...
@@ -7,7 +7,7 @@
#include "emitterstate.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/ostream
_wrapper
.h"
#include <string>
namespace
YAML
...
...
@@ -20,16 +20,16 @@ namespace YAML
{
StringFormat
::
value
ComputeStringFormat
(
const
std
::
string
&
str
,
EMITTER_MANIP
strFormat
,
FlowType
::
value
flowType
,
bool
escapeNonAscii
);
bool
WriteSingleQuotedString
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteDoubleQuotedString
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
escapeNonAscii
);
bool
WriteLiteralString
(
ostream
&
out
,
const
std
::
string
&
str
,
int
indent
);
bool
WriteChar
(
ostream
&
out
,
char
ch
);
bool
WriteComment
(
ostream
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
);
bool
WriteAlias
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteAnchor
(
ostream
&
out
,
const
std
::
string
&
str
);
bool
WriteTag
(
ostream
&
out
,
const
std
::
string
&
str
,
bool
verbatim
);
bool
WriteTagWithPrefix
(
ostream
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
);
bool
WriteBinary
(
ostream
&
out
,
const
Binary
&
binary
);
bool
WriteSingleQuotedString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
);
bool
WriteDoubleQuotedString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
bool
escapeNonAscii
);
bool
WriteLiteralString
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
int
indent
);
bool
WriteChar
(
ostream
_wrapper
&
out
,
char
ch
);
bool
WriteComment
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
int
postCommentIndent
);
bool
WriteAlias
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
);
bool
WriteAnchor
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
);
bool
WriteTag
(
ostream
_wrapper
&
out
,
const
std
::
string
&
str
,
bool
verbatim
);
bool
WriteTagWithPrefix
(
ostream
_wrapper
&
out
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tag
);
bool
WriteBinary
(
ostream
_wrapper
&
out
,
const
Binary
&
binary
);
}
}
...
...
src/indentation.h
View file @
a78069a6
...
...
@@ -6,7 +6,7 @@
#endif
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/ostream
_wrapper
.h"
#include <iostream>
namespace
YAML
...
...
@@ -16,7 +16,7 @@ namespace YAML
unsigned
n
;
};
inline
ostream
&
operator
<<
(
ostream
&
out
,
const
Indentation
&
indent
)
{
inline
ostream
_wrapper
&
operator
<<
(
ostream
_wrapper
&
out
,
const
Indentation
&
indent
)
{
for
(
unsigned
i
=
0
;
i
<
indent
.
n
;
i
++
)
out
<<
' '
;
return
out
;
...
...
@@ -27,7 +27,7 @@ namespace YAML
unsigned
n
;
};
inline
ostream
&
operator
<<
(
ostream
&
out
,
const
IndentTo
&
indent
)
{
inline
ostream
_wrapper
&
operator
<<
(
ostream
_wrapper
&
out
,
const
IndentTo
&
indent
)
{
while
(
out
.
col
()
<
indent
.
n
)
out
<<
' '
;
return
out
;
...
...
src/ostream.cpp
deleted
100644 → 0
View file @
4116d89f
#include "yaml-cpp/ostream.h"
#include <cstring>
namespace
YAML
{
ostream
::
ostream
()
:
m_buffer
(
0
),
m_pos
(
0
),
m_size
(
0
),
m_row
(
0
),
m_col
(
0
),
m_comment
(
false
)
{
reserve
(
1024
);
}
ostream
::~
ostream
()
{
delete
[]
m_buffer
;
}
void
ostream
::
reserve
(
unsigned
size
)
{
if
(
size
<=
m_size
)
return
;
char
*
newBuffer
=
new
char
[
size
];
std
::
memset
(
newBuffer
,
0
,
size
*
sizeof
(
char
));
std
::
memcpy
(
newBuffer
,
m_buffer
,
m_size
*
sizeof
(
char
));
delete
[]
m_buffer
;
m_buffer
=
newBuffer
;
m_size
=
size
;
}
void
ostream
::
put
(
char
ch
)
{
if
(
m_pos
>=
m_size
-
1
)
// an extra space for the NULL terminator
reserve
(
m_size
*
2
);
m_buffer
[
m_pos
]
=
ch
;
m_pos
++
;
if
(
ch
==
'\n'
)
{
m_row
++
;
m_col
=
0
;
m_comment
=
false
;
}
else
m_col
++
;
}
ostream
&
operator
<<
(
ostream
&
out
,
const
char
*
str
)
{
std
::
size_t
length
=
std
::
strlen
(
str
);
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
out
.
put
(
str
[
i
]);
return
out
;
}
ostream
&
operator
<<
(
ostream
&
out
,
const
std
::
string
&
str
)
{
out
<<
str
.
c_str
();
return
out
;
}
ostream
&
operator
<<
(
ostream
&
out
,
char
ch
)
{
out
.
put
(
ch
);
return
out
;
}
}
src/ostream_wrapper.cpp
0 → 100644
View file @
a78069a6
#include "yaml-cpp/ostream_wrapper.h"
#include <cstring>
#include <iostream>
namespace
YAML
{
ostream_wrapper
::
ostream_wrapper
()
:
m_pStream
(
0
),
m_pos
(
0
),
m_row
(
0
),
m_col
(
0
),
m_comment
(
false
)
{
}
ostream_wrapper
::
ostream_wrapper
(
std
::
ostream
&
stream
)
:
m_pStream
(
&
stream
),
m_pos
(
0
),
m_row
(
0
),
m_col
(
0
),
m_comment
(
false
)
{
}
ostream_wrapper
::~
ostream_wrapper
()
{
}
void
ostream_wrapper
::
write
(
const
std
::
string
&
str
)
{
if
(
m_pStream
)
{
m_pStream
->
write
(
str
.
c_str
(),
str
.
size
());
}
else
{
m_buffer
.
resize
(
std
::
max
(
m_buffer
.
size
(),
m_pos
+
str
.
size
()
+
1
));
std
::
copy
(
str
.
begin
(),
str
.
end
(),
&
m_buffer
[
m_pos
]);
}
for
(
std
::
size_t
i
=
0
;
i
<
str
.
size
();
i
++
)
update_pos
(
str
[
i
]);
}
void
ostream_wrapper
::
write
(
const
char
*
str
,
std
::
size_t
size
)
{
if
(
m_pStream
)
{
m_pStream
->
write
(
str
,
size
);
}
else
{
m_buffer
.
resize
(
std
::
max
(
m_buffer
.
size
(),
m_pos
+
size
+
1
));
std
::
copy
(
str
,
str
+
size
,
&
m_buffer
[
m_pos
]);
}
for
(
std
::
size_t
i
=
0
;
i
<
size
;
i
++
)
update_pos
(
str
[
i
]);
}
void
ostream_wrapper
::
update_pos
(
char
ch
)
{
m_pos
++
;
m_col
++
;
if
(
ch
==
'\n'
)
{
m_row
++
;
m_col
=
0
;
m_comment
=
false
;
}
}
}
util/sandbox.cpp
View file @
a78069a6
...
...
@@ -3,11 +3,10 @@
int
main
()
{
YAML
::
Emitter
out
;
YAML
::
Emitter
out
(
std
::
cout
)
;
out
<<
YAML
::
BeginSeq
;
out
<<
':'
;
out
<<
"item 1"
;
out
<<
YAML
::
BeginSeq
<<
"foo 1"
<<
"bar 2"
<<
YAML
::
EndSeq
;
out
<<
YAML
::
EndSeq
;
std
::
cout
<<
out
.
c_str
()
<<
"
\n
"
;
return
0
;
}
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