mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-03-03 12:58:03 +01:00
Minor changes to address msvc warnings and make cmake work on Windows
This commit is contained in:
parent
70f12ed1d4
commit
cb778b6bb6
@ -9,7 +9,20 @@ option(valijson_BUILD_TESTS "Build valijson test suite." TRUE)
|
|||||||
option(valijson_EXCLUDE_BOOST "Exclude Boost when building test suite." FALSE)
|
option(valijson_EXCLUDE_BOOST "Exclude Boost when building test suite." FALSE)
|
||||||
option(valijson_USE_EXCEPTIONS "Use exceptions in valijson and included libs." TRUE)
|
option(valijson_USE_EXCEPTIONS "Use exceptions in valijson and included libs." TRUE)
|
||||||
|
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
if(MSVC)
|
||||||
|
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
|
||||||
|
|
||||||
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||||
|
else()
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||||
|
if(!COMPILER_SUPPORTS_CXX11)
|
||||||
|
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||||
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(valijson INTERFACE)
|
add_library(valijson INTERFACE)
|
||||||
# create alias, so that user could always write target_link_libraries(... ValiJSON::valijson)
|
# create alias, so that user could always write target_link_libraries(... ValiJSON::valijson)
|
||||||
@ -29,16 +42,6 @@ if(NOT valijson_BUILD_TESTS AND NOT valijson_BUILD_EXAMPLES)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
||||||
if(COMPILER_SUPPORTS_CXX11)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#TODO()
|
#TODO()
|
||||||
if(valijson_USE_EXCEPTIONS)
|
if(valijson_USE_EXCEPTIONS)
|
||||||
add_definitions(-DVALIJSON_USE_EXCEPTIONS=1)
|
add_definitions(-DVALIJSON_USE_EXCEPTIONS=1)
|
||||||
@ -124,7 +127,11 @@ if(valijson_BUILD_TESTS)
|
|||||||
# Unit tests executable
|
# Unit tests executable
|
||||||
add_executable(test_suite ${TEST_SOURCES})
|
add_executable(test_suite ${TEST_SOURCES})
|
||||||
|
|
||||||
set_target_properties(test_suite PROPERTIES COMPILE_FLAGS " -pedantic -Werror -Wshadow -Wunused")
|
if(MSVC)
|
||||||
|
|
||||||
|
else()
|
||||||
|
set_target_properties(test_suite PROPERTIES COMPILE_FLAGS " -pedantic -Werror -Wshadow -Wunused")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Definition for using picojson
|
# Definition for using picojson
|
||||||
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
|
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
|
||||||
|
@ -27,7 +27,13 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable: 4706)
|
||||||
#include <picojson.h>
|
#include <picojson.h>
|
||||||
|
#pragma warning(default: 4706)
|
||||||
|
#else
|
||||||
|
#include <picojson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <valijson/adapters/adapter.hpp>
|
#include <valijson/adapters/adapter.hpp>
|
||||||
#include <valijson/adapters/basic_adapter.hpp>
|
#include <valijson/adapters/basic_adapter.hpp>
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable: 4706)
|
||||||
#include <picojson.h>
|
#include <picojson.h>
|
||||||
|
#pragma warning(default: 4706)
|
||||||
|
#else
|
||||||
|
#include <picojson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <valijson/utils/file_utils.hpp>
|
#include <valijson/utils/file_utils.hpp>
|
||||||
|
|
||||||
|
@ -1150,31 +1150,39 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const typename AdapterType::Array targetArray = m_target.asArray();
|
|
||||||
const typename AdapterType::Array::const_iterator end = targetArray.end();
|
|
||||||
|
|
||||||
bool validated = true;
|
bool validated = true;
|
||||||
const typename AdapterType::Array::const_iterator secondLast = --targetArray.end();
|
|
||||||
unsigned int outerIndex = 0;
|
|
||||||
typename AdapterType::Array::const_iterator outerItr = targetArray.begin();
|
|
||||||
for (; outerItr != secondLast; ++outerItr) {
|
|
||||||
unsigned int innerIndex = outerIndex + 1;
|
|
||||||
typename AdapterType::Array::const_iterator innerItr(outerItr);
|
|
||||||
for (++innerItr; innerItr != end; ++innerItr) {
|
|
||||||
if (outerItr->equalTo(*innerItr, true)) {
|
|
||||||
if (m_results) {
|
|
||||||
m_results->pushError(m_context, "Elements at indexes #" + std::to_string(outerIndex)
|
|
||||||
+ " and #" + std::to_string(innerIndex) + " violate uniqueness constraint.");
|
|
||||||
validated = false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++innerIndex;
|
|
||||||
}
|
|
||||||
++outerIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef VALIJSON_USE_EXCEPTIONS
|
||||||
|
try
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
const typename AdapterType::Array targetArray = m_target.asArray();
|
||||||
|
const typename AdapterType::Array::const_iterator end = targetArray.end();
|
||||||
|
const typename AdapterType::Array::const_iterator secondLast = --targetArray.end();
|
||||||
|
unsigned int outerIndex = 0;
|
||||||
|
typename AdapterType::Array::const_iterator outerItr = targetArray.begin();
|
||||||
|
for (; outerItr != secondLast; ++outerItr) {
|
||||||
|
unsigned int innerIndex = outerIndex + 1;
|
||||||
|
typename AdapterType::Array::const_iterator innerItr(outerItr);
|
||||||
|
for (++innerItr; innerItr != end; ++innerItr) {
|
||||||
|
if (outerItr->equalTo(*innerItr, true)) {
|
||||||
|
if (!m_results) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_results->pushError(m_context, "Elements at indexes #" + std::to_string(outerIndex)
|
||||||
|
+ " and #" + std::to_string(innerIndex) + " violate uniqueness constraint.");
|
||||||
|
validated = false;
|
||||||
|
}
|
||||||
|
++innerIndex;
|
||||||
|
}
|
||||||
|
++outerIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef VALIJSON_USE_EXCEPTIONS
|
||||||
|
catch (...) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return validated;
|
return validated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable: 4706)
|
||||||
#include <picojson.h>
|
#include <picojson.h>
|
||||||
|
#pragma warning(default: 4706)
|
||||||
|
#else
|
||||||
|
#include <picojson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool validate(
|
bool validate(
|
||||||
const Adapter &target,
|
const Adapter &,
|
||||||
const std::vector<std::string> &context,
|
const std::vector<std::string> &context,
|
||||||
ValidationResults *results) const override
|
ValidationResults *results) const override
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable: 4706)
|
||||||
#include <picojson.h>
|
#include <picojson.h>
|
||||||
|
#pragma warning(default: 4706)
|
||||||
|
#else
|
||||||
|
#include <picojson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user