From 0c8a5393618850a9ac1feabc3d73dff657f17ce0 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sat, 24 Jan 2015 14:38:22 -0600 Subject: [PATCH] Fix warnings on visual studio, including changing unsigned to std::size_t --- CMakeLists.txt | 2 +- include/yaml-cpp/emitter.h | 17 ++++++++-------- src/emitter.cpp | 40 +++++++++++++++++++------------------- src/emitterstate.cpp | 10 ++++++---- src/emitterstate.h | 16 +++++++-------- src/emitterutils.cpp | 2 +- src/indentation.h | 14 +++++++------ src/ostream_wrapper.cpp | 4 ++-- src/ptr_stack.h | 5 +++-- src/ptr_vector.h | 5 +++-- src/scanner.h | 7 ++++--- src/simplekey.cpp | 2 +- 12 files changed, 66 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c41335..1ab0f1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,7 @@ if(MSVC) # /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 # /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() diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index a8f56dc..cc49659 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -7,6 +7,7 @@ #pragma once #endif +#include #include #include #include @@ -48,11 +49,11 @@ class YAML_CPP_API Emitter : private noncopyable { bool SetIntBase(EMITTER_MANIP value); bool SetSeqFormat(EMITTER_MANIP value); bool SetMapFormat(EMITTER_MANIP value); - bool SetIndent(unsigned n); - bool SetPreCommentIndent(unsigned n); - bool SetPostCommentIndent(unsigned n); - bool SetFloatPrecision(unsigned n); - bool SetDoublePrecision(unsigned n); + bool SetIndent(std::size_t n); + bool SetPreCommentIndent(std::size_t n); + bool SetPostCommentIndent(std::size_t n); + bool SetFloatPrecision(std::size_t n); + bool SetDoublePrecision(std::size_t n); // local setters Emitter& SetLocalValue(EMITTER_MANIP value); @@ -79,8 +80,8 @@ class YAML_CPP_API Emitter : private noncopyable { private: template void SetStreamablePrecision(std::stringstream&) {} - unsigned GetFloatPrecision() const; - unsigned GetDoublePrecision() const; + std::size_t GetFloatPrecision() const; + std::size_t GetDoublePrecision() const; void PrepareIntegralStream(std::stringstream& stream) const; void StartedScalar(); @@ -115,7 +116,7 @@ class YAML_CPP_API Emitter : private noncopyable { void BlockMapPrepareSimpleKey(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; bool CanEmitNewline() const; diff --git a/src/emitter.cpp b/src/emitter.cpp index c666901..c942358 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -66,23 +66,23 @@ bool Emitter::SetMapFormat(EMITTER_MANIP value) { return ok; } -bool Emitter::SetIndent(unsigned n) { +bool Emitter::SetIndent(std::size_t n) { 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); } -bool Emitter::SetPostCommentIndent(unsigned n) { +bool Emitter::SetPostCommentIndent(std::size_t n) { 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); } -bool Emitter::SetDoublePrecision(unsigned n) { +bool Emitter::SetDoublePrecision(std::size_t n) { return m_pState->SetDoublePrecision(n, FmtScope::Global); } @@ -310,7 +310,7 @@ void Emitter::PrepareTopNode(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_stream.comment()) @@ -341,8 +341,8 @@ void Emitter::FlowSeqPrepareNode(EmitterNodeType::value child) { } void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child) { - const unsigned curIndent = m_pState->CurIndent(); - const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); + const std::size_t curIndent = m_pState->CurIndent(); + const std::size_t nextIndent = curIndent + m_pState->CurGroupIndent(); if (child == EmitterNodeType::None) return; @@ -392,7 +392,7 @@ void Emitter::FlowMapPrepareNode(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_stream.comment()) @@ -423,7 +423,7 @@ void Emitter::FlowMapPrepareLongKey(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_stream.comment()) @@ -451,7 +451,7 @@ void Emitter::FlowMapPrepareLongKeyValue(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_stream.comment()) @@ -482,7 +482,7 @@ void Emitter::FlowMapPrepareSimpleKey(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_stream.comment()) @@ -530,7 +530,7 @@ void Emitter::BlockMapPrepareNode(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(); if (child == EmitterNodeType::None) @@ -563,7 +563,7 @@ void Emitter::BlockMapPrepareLongKey(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) return; @@ -589,7 +589,7 @@ void Emitter::BlockMapPrepareLongKeyValue(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(); if (child == EmitterNodeType::None) @@ -617,8 +617,8 @@ void Emitter::BlockMapPrepareSimpleKey(EmitterNodeType::value child) { } void Emitter::BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child) { - const unsigned curIndent = m_pState->CurIndent(); - const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); + const std::size_t curIndent = m_pState->CurIndent(); + const std::size_t nextIndent = curIndent + m_pState->CurGroupIndent(); if (!m_pState->HasBegunNode()) { m_stream << ":"; @@ -642,7 +642,7 @@ void Emitter::BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child) { // SpaceOrIndentTo // . 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()) m_stream << "\n"; if (m_stream.col() > 0 && requireSpace) @@ -709,11 +709,11 @@ Emitter& Emitter::Write(const std::string& str) { return *this; } -unsigned Emitter::GetFloatPrecision() const { +std::size_t Emitter::GetFloatPrecision() const { return m_pState->GetFloatPrecision(); } -unsigned Emitter::GetDoublePrecision() const { +std::size_t Emitter::GetDoublePrecision() const { return m_pState->GetDoublePrecision(); } diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index 80ffa64..1836565 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -155,7 +155,7 @@ void EmitterState::EndedGroup(GroupType::value type) { } // 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); 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) return false; @@ -284,7 +284,8 @@ bool EmitterState::SetIndent(unsigned value, FmtScope::value scope) { return true; } -bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope) { +bool EmitterState::SetPreCommentIndent(std::size_t value, + FmtScope::value scope) { if (value == 0) return false; @@ -292,7 +293,8 @@ bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope) { return true; } -bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope) { +bool EmitterState::SetPostCommentIndent(std::size_t value, + FmtScope::value scope) { if (value == 0) return false; diff --git a/src/emitterstate.h b/src/emitterstate.h index 7518263..3f56116 100644 --- a/src/emitterstate.h +++ b/src/emitterstate.h @@ -94,12 +94,12 @@ class EmitterState { bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope); 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(); } - bool SetPreCommentIndent(unsigned value, FmtScope::value scope); + bool SetPreCommentIndent(std::size_t value, FmtScope::value scope); 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(); } bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, @@ -110,9 +110,9 @@ class EmitterState { EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); } 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); - unsigned GetDoublePrecision() const { return m_doublePrecision.get(); } + std::size_t GetDoublePrecision() const { return m_doublePrecision.get(); } private: template @@ -132,8 +132,8 @@ class EmitterState { Setting m_boolLengthFmt; Setting m_boolCaseFmt; Setting m_intFmt; - Setting m_indent; - Setting m_preCommentIndent, m_postCommentIndent; + Setting m_indent; + Setting m_preCommentIndent, m_postCommentIndent; Setting m_seqFmt; Setting m_mapFmt; Setting m_mapKeyFmt; @@ -175,7 +175,7 @@ class EmitterState { }; ptr_stack m_groups; - unsigned m_curIndent; + std::size_t m_curIndent; bool m_hasAnchor; bool m_hasTag; bool m_hasNonContent; diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index 4473aea..55aa51c 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -358,7 +358,7 @@ bool WriteChar(ostream_wrapper& out, char ch) { bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent) { - const unsigned curIndent = out.col(); + const std::size_t curIndent = out.col(); out << "#" << Indentation(postCommentIndent); out.set_comment(); int codePoint; diff --git a/src/indentation.h b/src/indentation.h index a92ad56..1a2ccae 100644 --- a/src/indentation.h +++ b/src/indentation.h @@ -7,25 +7,27 @@ #pragma once #endif -#include "yaml-cpp/ostream_wrapper.h" #include +#include + +#include "yaml-cpp/ostream_wrapper.h" namespace YAML { struct Indentation { - Indentation(unsigned n_) : n(n_) {} - unsigned n; + Indentation(std::size_t n_) : n(n_) {} + std::size_t n; }; inline ostream_wrapper& operator<<(ostream_wrapper& out, const Indentation& indent) { - for (unsigned i = 0; i < indent.n; i++) + for (std::size_t i = 0; i < indent.n; i++) out << ' '; return out; } struct IndentTo { - IndentTo(unsigned n_) : n(n_) {} - unsigned n; + IndentTo(std::size_t n_) : n(n_) {} + std::size_t n; }; inline ostream_wrapper& operator<<(ostream_wrapper& out, diff --git a/src/ostream_wrapper.cpp b/src/ostream_wrapper.cpp index 7f7adae..357fc00 100644 --- a/src/ostream_wrapper.cpp +++ b/src/ostream_wrapper.cpp @@ -23,7 +23,7 @@ void ostream_wrapper::write(const std::string& str) { 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]); + std::copy(str.begin(), str.end(), m_buffer.begin() + m_pos); } 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); } else { 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++) { diff --git a/src/ptr_stack.h b/src/ptr_stack.h index f423b01..f378ffc 100644 --- a/src/ptr_stack.h +++ b/src/ptr_stack.h @@ -7,12 +7,13 @@ #pragma once #endif -#include "yaml-cpp/noncopyable.h" #include #include #include #include +#include "yaml-cpp/noncopyable.h" + template class ptr_stack : private YAML::noncopyable { public: @@ -20,7 +21,7 @@ class ptr_stack : private YAML::noncopyable { ~ptr_stack() { 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]; m_data.clear(); } diff --git a/src/ptr_vector.h b/src/ptr_vector.h index 4b5081c..a546a89 100644 --- a/src/ptr_vector.h +++ b/src/ptr_vector.h @@ -7,12 +7,13 @@ #pragma once #endif -#include "yaml-cpp/noncopyable.h" #include #include #include #include +#include "yaml-cpp/noncopyable.h" + namespace YAML { template @@ -22,7 +23,7 @@ class ptr_vector : private YAML::noncopyable { ~ptr_vector() { 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]; m_data.clear(); } diff --git a/src/scanner.h b/src/scanner.h index fd740f4..b0ac6d9 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -7,6 +7,7 @@ #pragma once #endif +#include #include #include #include @@ -60,7 +61,7 @@ class Scanner { bool InFlowContext() 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; IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type); @@ -83,13 +84,13 @@ class Scanner { const RegEx &GetValueRegex() const; struct SimpleKey { - SimpleKey(const Mark &mark_, int flowLevel_); + SimpleKey(const Mark &mark_, std::size_t flowLevel_); void Validate(); void Invalidate(); Mark mark; - int flowLevel; + std::size_t flowLevel; IndentMarker *pIndent; Token *pMapStart, *pKey; }; diff --git a/src/simplekey.cpp b/src/simplekey.cpp index bec8720..70f56b6 100644 --- a/src/simplekey.cpp +++ b/src/simplekey.cpp @@ -4,7 +4,7 @@ namespace YAML { 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) {} void Scanner::SimpleKey::Validate() {