Fix warnings on visual studio, including changing unsigned to std::size_t

This commit is contained in:
Jesse Beder 2015-01-24 14:38:22 -06:00
parent ad712c4f2d
commit 0c8a539361
12 changed files with 66 additions and 58 deletions

View File

@ -238,7 +238,7 @@ if(MSVC)
# /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx # /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
# /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx # /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx
# /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx # /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
set(yaml_cxx_flags "/W3 /wd4127 /wd4355 /D_SCL_SECURE_NO_WARNINGS ${yaml_cxx_flags}") set(yaml_cxx_flags "/W3 /wd4127 /wd4355 ${yaml_cxx_flags}")
endif() endif()

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#endif #endif
#include <cstddef>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -48,11 +49,11 @@ class YAML_CPP_API Emitter : private noncopyable {
bool SetIntBase(EMITTER_MANIP value); bool SetIntBase(EMITTER_MANIP value);
bool SetSeqFormat(EMITTER_MANIP value); bool SetSeqFormat(EMITTER_MANIP value);
bool SetMapFormat(EMITTER_MANIP value); bool SetMapFormat(EMITTER_MANIP value);
bool SetIndent(unsigned n); bool SetIndent(std::size_t n);
bool SetPreCommentIndent(unsigned n); bool SetPreCommentIndent(std::size_t n);
bool SetPostCommentIndent(unsigned n); bool SetPostCommentIndent(std::size_t n);
bool SetFloatPrecision(unsigned n); bool SetFloatPrecision(std::size_t n);
bool SetDoublePrecision(unsigned n); bool SetDoublePrecision(std::size_t n);
// local setters // local setters
Emitter& SetLocalValue(EMITTER_MANIP value); Emitter& SetLocalValue(EMITTER_MANIP value);
@ -79,8 +80,8 @@ class YAML_CPP_API Emitter : private noncopyable {
private: private:
template <typename T> template <typename T>
void SetStreamablePrecision(std::stringstream&) {} void SetStreamablePrecision(std::stringstream&) {}
unsigned GetFloatPrecision() const; std::size_t GetFloatPrecision() const;
unsigned GetDoublePrecision() const; std::size_t GetDoublePrecision() const;
void PrepareIntegralStream(std::stringstream& stream) const; void PrepareIntegralStream(std::stringstream& stream) const;
void StartedScalar(); void StartedScalar();
@ -115,7 +116,7 @@ class YAML_CPP_API Emitter : private noncopyable {
void BlockMapPrepareSimpleKey(EmitterNodeType::value child); void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child); void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void SpaceOrIndentTo(bool requireSpace, unsigned indent); void SpaceOrIndentTo(bool requireSpace, std::size_t indent);
const char* ComputeFullBoolName(bool b) const; const char* ComputeFullBoolName(bool b) const;
bool CanEmitNewline() const; bool CanEmitNewline() const;

View File

@ -66,23 +66,23 @@ bool Emitter::SetMapFormat(EMITTER_MANIP value) {
return ok; return ok;
} }
bool Emitter::SetIndent(unsigned n) { bool Emitter::SetIndent(std::size_t n) {
return m_pState->SetIndent(n, FmtScope::Global); return m_pState->SetIndent(n, FmtScope::Global);
} }
bool Emitter::SetPreCommentIndent(unsigned n) { bool Emitter::SetPreCommentIndent(std::size_t n) {
return m_pState->SetPreCommentIndent(n, FmtScope::Global); return m_pState->SetPreCommentIndent(n, FmtScope::Global);
} }
bool Emitter::SetPostCommentIndent(unsigned n) { bool Emitter::SetPostCommentIndent(std::size_t n) {
return m_pState->SetPostCommentIndent(n, FmtScope::Global); return m_pState->SetPostCommentIndent(n, FmtScope::Global);
} }
bool Emitter::SetFloatPrecision(unsigned n) { bool Emitter::SetFloatPrecision(std::size_t n) {
return m_pState->SetFloatPrecision(n, FmtScope::Global); return m_pState->SetFloatPrecision(n, FmtScope::Global);
} }
bool Emitter::SetDoublePrecision(unsigned n) { bool Emitter::SetDoublePrecision(std::size_t n) {
return m_pState->SetDoublePrecision(n, FmtScope::Global); return m_pState->SetDoublePrecision(n, FmtScope::Global);
} }
@ -310,7 +310,7 @@ void Emitter::PrepareTopNode(EmitterNodeType::value child) {
} }
void Emitter::FlowSeqPrepareNode(EmitterNodeType::value child) { void Emitter::FlowSeqPrepareNode(EmitterNodeType::value child) {
const unsigned lastIndent = m_pState->LastIndent(); const std::size_t lastIndent = m_pState->LastIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
if (m_stream.comment()) if (m_stream.comment())
@ -341,8 +341,8 @@ void Emitter::FlowSeqPrepareNode(EmitterNodeType::value child) {
} }
void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child) { void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child) {
const unsigned curIndent = m_pState->CurIndent(); const std::size_t curIndent = m_pState->CurIndent();
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); const std::size_t nextIndent = curIndent + m_pState->CurGroupIndent();
if (child == EmitterNodeType::None) if (child == EmitterNodeType::None)
return; return;
@ -392,7 +392,7 @@ void Emitter::FlowMapPrepareNode(EmitterNodeType::value child) {
} }
void Emitter::FlowMapPrepareLongKey(EmitterNodeType::value child) { void Emitter::FlowMapPrepareLongKey(EmitterNodeType::value child) {
const unsigned lastIndent = m_pState->LastIndent(); const std::size_t lastIndent = m_pState->LastIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
if (m_stream.comment()) if (m_stream.comment())
@ -423,7 +423,7 @@ void Emitter::FlowMapPrepareLongKey(EmitterNodeType::value child) {
} }
void Emitter::FlowMapPrepareLongKeyValue(EmitterNodeType::value child) { void Emitter::FlowMapPrepareLongKeyValue(EmitterNodeType::value child) {
const unsigned lastIndent = m_pState->LastIndent(); const std::size_t lastIndent = m_pState->LastIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
if (m_stream.comment()) if (m_stream.comment())
@ -451,7 +451,7 @@ void Emitter::FlowMapPrepareLongKeyValue(EmitterNodeType::value child) {
} }
void Emitter::FlowMapPrepareSimpleKey(EmitterNodeType::value child) { void Emitter::FlowMapPrepareSimpleKey(EmitterNodeType::value child) {
const unsigned lastIndent = m_pState->LastIndent(); const std::size_t lastIndent = m_pState->LastIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
if (m_stream.comment()) if (m_stream.comment())
@ -482,7 +482,7 @@ void Emitter::FlowMapPrepareSimpleKey(EmitterNodeType::value child) {
} }
void Emitter::FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child) { void Emitter::FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child) {
const unsigned lastIndent = m_pState->LastIndent(); const std::size_t lastIndent = m_pState->LastIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
if (m_stream.comment()) if (m_stream.comment())
@ -530,7 +530,7 @@ void Emitter::BlockMapPrepareNode(EmitterNodeType::value child) {
} }
void Emitter::BlockMapPrepareLongKey(EmitterNodeType::value child) { void Emitter::BlockMapPrepareLongKey(EmitterNodeType::value child) {
const unsigned curIndent = m_pState->CurIndent(); const std::size_t curIndent = m_pState->CurIndent();
const std::size_t childCount = m_pState->CurGroupChildCount(); const std::size_t childCount = m_pState->CurGroupChildCount();
if (child == EmitterNodeType::None) if (child == EmitterNodeType::None)
@ -563,7 +563,7 @@ void Emitter::BlockMapPrepareLongKey(EmitterNodeType::value child) {
} }
void Emitter::BlockMapPrepareLongKeyValue(EmitterNodeType::value child) { void Emitter::BlockMapPrepareLongKeyValue(EmitterNodeType::value child) {
const unsigned curIndent = m_pState->CurIndent(); const std::size_t curIndent = m_pState->CurIndent();
if (child == EmitterNodeType::None) if (child == EmitterNodeType::None)
return; return;
@ -589,7 +589,7 @@ void Emitter::BlockMapPrepareLongKeyValue(EmitterNodeType::value child) {
} }
void Emitter::BlockMapPrepareSimpleKey(EmitterNodeType::value child) { void Emitter::BlockMapPrepareSimpleKey(EmitterNodeType::value child) {
const unsigned curIndent = m_pState->CurIndent(); const std::size_t curIndent = m_pState->CurIndent();
const std::size_t childCount = m_pState->CurGroupChildCount(); const std::size_t childCount = m_pState->CurGroupChildCount();
if (child == EmitterNodeType::None) if (child == EmitterNodeType::None)
@ -617,8 +617,8 @@ void Emitter::BlockMapPrepareSimpleKey(EmitterNodeType::value child) {
} }
void Emitter::BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child) { void Emitter::BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child) {
const unsigned curIndent = m_pState->CurIndent(); const std::size_t curIndent = m_pState->CurIndent();
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); const std::size_t nextIndent = curIndent + m_pState->CurGroupIndent();
if (!m_pState->HasBegunNode()) { if (!m_pState->HasBegunNode()) {
m_stream << ":"; m_stream << ":";
@ -642,7 +642,7 @@ void Emitter::BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child) {
// SpaceOrIndentTo // SpaceOrIndentTo
// . Prepares for some more content by proper spacing // . Prepares for some more content by proper spacing
void Emitter::SpaceOrIndentTo(bool requireSpace, unsigned indent) { void Emitter::SpaceOrIndentTo(bool requireSpace, std::size_t indent) {
if (m_stream.comment()) if (m_stream.comment())
m_stream << "\n"; m_stream << "\n";
if (m_stream.col() > 0 && requireSpace) if (m_stream.col() > 0 && requireSpace)
@ -709,11 +709,11 @@ Emitter& Emitter::Write(const std::string& str) {
return *this; return *this;
} }
unsigned Emitter::GetFloatPrecision() const { std::size_t Emitter::GetFloatPrecision() const {
return m_pState->GetFloatPrecision(); return m_pState->GetFloatPrecision();
} }
unsigned Emitter::GetDoublePrecision() const { std::size_t Emitter::GetDoublePrecision() const {
return m_pState->GetDoublePrecision(); return m_pState->GetDoublePrecision();
} }

View File

@ -155,7 +155,7 @@ void EmitterState::EndedGroup(GroupType::value type) {
} }
// reset old settings // reset old settings
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent); std::size_t lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
assert(m_curIndent >= lastIndent); assert(m_curIndent >= lastIndent);
m_curIndent -= lastIndent; m_curIndent -= lastIndent;
@ -276,7 +276,7 @@ bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope) {
} }
} }
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope) { bool EmitterState::SetIndent(std::size_t value, FmtScope::value scope) {
if (value <= 1) if (value <= 1)
return false; return false;
@ -284,7 +284,8 @@ bool EmitterState::SetIndent(unsigned value, FmtScope::value scope) {
return true; return true;
} }
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope) { bool EmitterState::SetPreCommentIndent(std::size_t value,
FmtScope::value scope) {
if (value == 0) if (value == 0)
return false; return false;
@ -292,7 +293,8 @@ bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope) {
return true; return true;
} }
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope) { bool EmitterState::SetPostCommentIndent(std::size_t value,
FmtScope::value scope) {
if (value == 0) if (value == 0)
return false; return false;

View File

@ -94,12 +94,12 @@ class EmitterState {
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope); bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); } EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
bool SetIndent(unsigned value, FmtScope::value scope); bool SetIndent(std::size_t value, FmtScope::value scope);
int GetIndent() const { return m_indent.get(); } int GetIndent() const { return m_indent.get(); }
bool SetPreCommentIndent(unsigned value, FmtScope::value scope); bool SetPreCommentIndent(std::size_t value, FmtScope::value scope);
int GetPreCommentIndent() const { return m_preCommentIndent.get(); } int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
bool SetPostCommentIndent(unsigned value, FmtScope::value scope); bool SetPostCommentIndent(std::size_t value, FmtScope::value scope);
int GetPostCommentIndent() const { return m_postCommentIndent.get(); } int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value,
@ -110,9 +110,9 @@ class EmitterState {
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); } EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
bool SetFloatPrecision(int value, FmtScope::value scope); bool SetFloatPrecision(int value, FmtScope::value scope);
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); } std::size_t GetFloatPrecision() const { return m_floatPrecision.get(); }
bool SetDoublePrecision(int value, FmtScope::value scope); bool SetDoublePrecision(int value, FmtScope::value scope);
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); } std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); }
private: private:
template <typename T> template <typename T>
@ -132,8 +132,8 @@ class EmitterState {
Setting<EMITTER_MANIP> m_boolLengthFmt; Setting<EMITTER_MANIP> m_boolLengthFmt;
Setting<EMITTER_MANIP> m_boolCaseFmt; Setting<EMITTER_MANIP> m_boolCaseFmt;
Setting<EMITTER_MANIP> m_intFmt; Setting<EMITTER_MANIP> m_intFmt;
Setting<unsigned> m_indent; Setting<std::size_t> m_indent;
Setting<unsigned> m_preCommentIndent, m_postCommentIndent; Setting<std::size_t> m_preCommentIndent, m_postCommentIndent;
Setting<EMITTER_MANIP> m_seqFmt; Setting<EMITTER_MANIP> m_seqFmt;
Setting<EMITTER_MANIP> m_mapFmt; Setting<EMITTER_MANIP> m_mapFmt;
Setting<EMITTER_MANIP> m_mapKeyFmt; Setting<EMITTER_MANIP> m_mapKeyFmt;
@ -175,7 +175,7 @@ class EmitterState {
}; };
ptr_stack<Group> m_groups; ptr_stack<Group> m_groups;
unsigned m_curIndent; std::size_t m_curIndent;
bool m_hasAnchor; bool m_hasAnchor;
bool m_hasTag; bool m_hasTag;
bool m_hasNonContent; bool m_hasNonContent;

View File

@ -358,7 +358,7 @@ bool WriteChar(ostream_wrapper& out, char ch) {
bool WriteComment(ostream_wrapper& out, const std::string& str, bool WriteComment(ostream_wrapper& out, const std::string& str,
int postCommentIndent) { int postCommentIndent) {
const unsigned curIndent = out.col(); const std::size_t curIndent = out.col();
out << "#" << Indentation(postCommentIndent); out << "#" << Indentation(postCommentIndent);
out.set_comment(); out.set_comment();
int codePoint; int codePoint;

View File

@ -7,25 +7,27 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/ostream_wrapper.h"
#include <iostream> #include <iostream>
#include <cstddef>
#include "yaml-cpp/ostream_wrapper.h"
namespace YAML { namespace YAML {
struct Indentation { struct Indentation {
Indentation(unsigned n_) : n(n_) {} Indentation(std::size_t n_) : n(n_) {}
unsigned n; std::size_t n;
}; };
inline ostream_wrapper& operator<<(ostream_wrapper& out, inline ostream_wrapper& operator<<(ostream_wrapper& out,
const Indentation& indent) { const Indentation& indent) {
for (unsigned i = 0; i < indent.n; i++) for (std::size_t i = 0; i < indent.n; i++)
out << ' '; out << ' ';
return out; return out;
} }
struct IndentTo { struct IndentTo {
IndentTo(unsigned n_) : n(n_) {} IndentTo(std::size_t n_) : n(n_) {}
unsigned n; std::size_t n;
}; };
inline ostream_wrapper& operator<<(ostream_wrapper& out, inline ostream_wrapper& operator<<(ostream_wrapper& out,

View File

@ -23,7 +23,7 @@ void ostream_wrapper::write(const std::string& str) {
m_pStream->write(str.c_str(), str.size()); m_pStream->write(str.c_str(), str.size());
} else { } else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1)); m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
std::copy(str.begin(), str.end(), &m_buffer[m_pos]); std::copy(str.begin(), str.end(), m_buffer.begin() + m_pos);
} }
for (std::size_t i = 0; i < str.size(); i++) { for (std::size_t i = 0; i < str.size(); i++) {
@ -36,7 +36,7 @@ void ostream_wrapper::write(const char* str, std::size_t size) {
m_pStream->write(str, size); m_pStream->write(str, size);
} else { } else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1)); m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
std::copy(str, str + size, &m_buffer[m_pos]); std::copy(str, str + size, m_buffer.begin() + m_pos);
} }
for (std::size_t i = 0; i < size; i++) { for (std::size_t i = 0; i < size; i++) {

View File

@ -7,12 +7,13 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef> #include <cstddef>
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "yaml-cpp/noncopyable.h"
template <typename T> template <typename T>
class ptr_stack : private YAML::noncopyable { class ptr_stack : private YAML::noncopyable {
public: public:
@ -20,7 +21,7 @@ class ptr_stack : private YAML::noncopyable {
~ptr_stack() { clear(); } ~ptr_stack() { clear(); }
void clear() { void clear() {
for (unsigned i = 0; i < m_data.size(); i++) for (std::size_t i = 0; i < m_data.size(); i++)
delete m_data[i]; delete m_data[i];
m_data.clear(); m_data.clear();
} }

View File

@ -7,12 +7,13 @@
#pragma once #pragma once
#endif #endif
#include "yaml-cpp/noncopyable.h"
#include <cstddef> #include <cstddef>
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "yaml-cpp/noncopyable.h"
namespace YAML { namespace YAML {
template <typename T> template <typename T>
@ -22,7 +23,7 @@ class ptr_vector : private YAML::noncopyable {
~ptr_vector() { clear(); } ~ptr_vector() { clear(); }
void clear() { void clear() {
for (unsigned i = 0; i < m_data.size(); i++) for (std::size_t i = 0; i < m_data.size(); i++)
delete m_data[i]; delete m_data[i];
m_data.clear(); m_data.clear();
} }

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#endif #endif
#include <cstddef>
#include <ios> #include <ios>
#include <map> #include <map>
#include <queue> #include <queue>
@ -60,7 +61,7 @@ class Scanner {
bool InFlowContext() const { return !m_flows.empty(); } bool InFlowContext() const { return !m_flows.empty(); }
bool InBlockContext() const { return m_flows.empty(); } bool InBlockContext() const { return m_flows.empty(); }
int GetFlowLevel() const { return m_flows.size(); } std::size_t GetFlowLevel() const { return m_flows.size(); }
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const; Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const;
IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type); IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type);
@ -83,13 +84,13 @@ class Scanner {
const RegEx &GetValueRegex() const; const RegEx &GetValueRegex() const;
struct SimpleKey { struct SimpleKey {
SimpleKey(const Mark &mark_, int flowLevel_); SimpleKey(const Mark &mark_, std::size_t flowLevel_);
void Validate(); void Validate();
void Invalidate(); void Invalidate();
Mark mark; Mark mark;
int flowLevel; std::size_t flowLevel;
IndentMarker *pIndent; IndentMarker *pIndent;
Token *pMapStart, *pKey; Token *pMapStart, *pKey;
}; };

View File

@ -4,7 +4,7 @@
namespace YAML { namespace YAML {
struct Mark; struct Mark;
Scanner::SimpleKey::SimpleKey(const Mark& mark_, int flowLevel_) Scanner::SimpleKey::SimpleKey(const Mark& mark_, std::size_t flowLevel_)
: mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {} : mark(mark_), flowLevel(flowLevel_), pIndent(0), pMapStart(0), pKey(0) {}
void Scanner::SimpleKey::Validate() { void Scanner::SimpleKey::Validate() {