some fixes and cleanup

This commit is contained in:
Niels 2015-02-13 21:46:33 +01:00
parent 36e36bf84a
commit 005a5c2858
5 changed files with 395 additions and 775 deletions

View file

@ -9,11 +9,7 @@ before_install:
- if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.9; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
- sudo pip install cpp-coveralls pyyaml
- sudo apt-get install valgrind re2c
before_script:
- autoreconf -iv
- ./configure
- sudo apt-get install valgrind
script:
- make

View file

@ -1,32 +0,0 @@
.PHONY: header_only
noinst_PROGRAMS = json_unit
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder
json_unit_SOURCES = src/json.hpp test/catch.hpp test/unit.cpp
json_unit_CXXFLAGS = $(FLAGS) -std=c++11
json_unit_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/test -Dprivate=public
# parameters:
# -b use bit vectors
# -s nested ifs
# -i do not create #line information
# --no-generation-date suppress generation date output
src/json.hpp: src/json.hpp.re2c
$(AM_V_GEN)$(RE2C) -b -s -i --no-generation-date $< | $(SED) '1d' > $@
cppcheck:
cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp
svn-clean: maintainer-clean
rm -fr configure INSTALL aclocal.m4 build-aux depcomp install-sh missing test-driver
for DIR in $(DIST_SUBDIRS) .; do rm -f $$DIR/Makefile.in; done
pretty:
astyle --style=allman --indent=spaces=4 --indent-modifiers \
--indent-switches --indent-preproc-block --indent-preproc-define \
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none \
src/json.hpp src/json.hpp.re2c test/unit.cpp

View file

@ -1,14 +0,0 @@
AC_INIT([JSON], [3.0], [mail@nlohmann.me])
AC_CONFIG_SRCDIR([src/json.hpp.re2c])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_SILENT_RULES([yes])
AC_PROG_CXX
AC_PROG_SED
AM_MISSING_PROG(RE2C, [re2c])
AM_MISSING_PROG(CPPCHECK, [cppcheck])
AM_MISSING_PROG(ASTYLE, [astyle])
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

File diff suppressed because it is too large Load diff

View file

@ -454,7 +454,12 @@ class basic_json
}
/// copy assignment
inline reference& operator=(basic_json other) noexcept
inline reference& operator=(basic_json other) noexcept (
std::is_nothrow_move_constructible<value_t>::value and
std::is_nothrow_move_assignable<value_t>::value and
std::is_nothrow_move_constructible<json_value>::value and
std::is_nothrow_move_assignable<json_value>::value
)
{
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
@ -1043,7 +1048,12 @@ class basic_json
}
/// swaps the contents
inline void swap(reference other) noexcept
inline void swap(reference other) noexcept (
std::is_nothrow_move_constructible<value_t>::value and
std::is_nothrow_move_assignable<value_t>::value and
std::is_nothrow_move_constructible<json_value>::value and
std::is_nothrow_move_assignable<json_value>::value
)
{
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
@ -1464,10 +1474,13 @@ class basic_json
inline string_t dump(const bool prettyPrint, const unsigned int indentStep,
unsigned int currentIndent = 0) const noexcept
{
// variable to hold indentation for recursive calls
auto new_indent = currentIndent;
// helper function to return whitespace as indentation
const auto indent = [prettyPrint, &currentIndent]()
const auto indent = [prettyPrint, &new_indent]()
{
return prettyPrint ? string_t(currentIndent, ' ') : string_t();
return prettyPrint ? string_t(new_indent, ' ') : string_t();
};
switch (m_type)
@ -1484,7 +1497,7 @@ class basic_json
// increase indentation
if (prettyPrint)
{
currentIndent += indentStep;
new_indent += indentStep;
result += "\n";
}
@ -1495,13 +1508,13 @@ class basic_json
result += prettyPrint ? ",\n" : ",";
}
result += indent() + "\"" + escape_string(i->first) + "\":" + (prettyPrint ? " " : "")
+ i->second.dump(prettyPrint, indentStep, currentIndent);
+ i->second.dump(prettyPrint, indentStep, new_indent);
}
// decrease indentation
if (prettyPrint)
{
currentIndent -= indentStep;
new_indent -= indentStep;
result += "\n";
}
@ -1520,7 +1533,7 @@ class basic_json
// increase indentation
if (prettyPrint)
{
currentIndent += indentStep;
new_indent += indentStep;
result += "\n";
}
@ -1530,13 +1543,13 @@ class basic_json
{
result += prettyPrint ? ",\n" : ",";
}
result += indent() + i->dump(prettyPrint, indentStep, currentIndent);
result += indent() + i->dump(prettyPrint, indentStep, new_indent);
}
// decrease indentation
if (prettyPrint)
{
currentIndent -= indentStep;
new_indent -= indentStep;
result += "\n";
}