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
7c85e9d5
Commit
7c85e9d5
authored
May 25, 2012
by
Jesse Beder
Browse files
Updated ostream wrapper with a write() and update_pos
parent
1602f789
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
15 deletions
+46
-15
include/yaml-cpp/ostream_wrapper.h
include/yaml-cpp/ostream_wrapper.h
+13
-7
src/ostream_wrapper.cpp
src/ostream_wrapper.cpp
+33
-8
No files found.
include/yaml-cpp/ostream_wrapper.h
View file @
7c85e9d5
...
...
@@ -16,22 +16,28 @@ namespace YAML
ostream_wrapper
();
~
ostream_wrapper
();
void
reserve
(
unsigned
size
);
void
reserve
(
std
::
size_t
size
);
void
write
(
const
std
::
string
&
str
);
void
write
(
const
char
*
str
,
std
::
size_t
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
;
}
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:
char
*
m_buffer
;
unsigned
m_pos
;
unsigned
m_size
;
std
::
size_t
m_pos
;
std
::
size_t
m_size
;
unsigned
m_row
,
m_col
;
std
::
size_t
m_row
,
m_col
;
bool
m_comment
;
};
...
...
src/ostream_wrapper.cpp
View file @
7c85e9d5
...
...
@@ -13,7 +13,7 @@ namespace YAML
delete
[]
m_buffer
;
}
void
ostream_wrapper
::
reserve
(
unsigned
size
)
void
ostream_wrapper
::
reserve
(
std
::
size_t
size
)
{
if
(
size
<=
m_size
)
return
;
...
...
@@ -26,33 +26,58 @@ namespace YAML
m_size
=
size
;
}
void
ostream_wrapper
::
write
(
const
std
::
string
&
str
)
{
while
(
m_pos
+
str
.
size
()
+
1
>=
m_size
)
reserve
(
m_size
*
2
);
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
)
{
while
(
m_pos
+
size
+
1
>=
m_size
)
reserve
(
m_size
*
2
);
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
::
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
;
update_pos
(
ch
);
}
void
ostream_wrapper
::
update_pos
(
char
ch
)
{
m_pos
++
;
m_col
++
;
if
(
ch
==
'\n'
)
{
m_row
++
;
m_col
=
0
;
m_comment
=
false
;
}
else
m_col
++
;
}
}
ostream_wrapper
&
operator
<<
(
ostream_wrapper
&
out
,
const
char
*
str
)
{
std
::
size_t
length
=
std
::
strlen
(
str
);
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
out
.
put
(
str
[
i
]);
out
.
write
(
str
,
std
::
strlen
(
str
));
return
out
;
}
ostream_wrapper
&
operator
<<
(
ostream_wrapper
&
out
,
const
std
::
string
&
str
)
{
out
<<
str
.
c_
str
(
);
out
.
write
(
str
);
return
out
;
}
...
...
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