diff --git a/Makefile b/Makefile index 39ffee92b..8fd95dca1 100644 --- a/Makefile +++ b/Makefile @@ -2,66 +2,43 @@ RE2C = re2c SED = sed -# additional flags -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 -Wdeprecated -Wfloat-equal - +# main target all: json_unit # clean up clean: rm -f json_unit json_benchmarks + +########################################################################## +# unit tests +########################################################################## + +# additional flags +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 -Wdeprecated -Wfloat-equal + # build unit tests json_unit: test/unit.cpp src/json.hpp test/catch.hpp $(CXX) -std=c++11 $(CXXFLAGS) $(FLAGS) $(CPPFLAGS) -I src -I test $< $(LDFLAGS) -o $@ -# execute the unit tests and check documentation -check: json_unit - ./json_unit "*" - make check -C docs/examples -doxygen: update_docs src/json.hpp - doxygen - gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html - gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html +########################################################################## +# static analyzer +########################################################################## -docset: update_docs src/json.hpp - cp Doxyfile Doxyfile_docset - gsed -i 's/DISABLE_INDEX = NO/DISABLE_INDEX = YES/' Doxyfile_docset - gsed -i 's/SEARCHENGINE = YES/SEARCHENGINE = NO/' Doxyfile_docset - gsed -i 's/GENERATE_TREEVIEW = YES/GENERATE_TREEVIEW = NO/' Doxyfile_docset - gsed -i 's/BINARY_TOC = YES/BINARY_TOC = NO/' Doxyfile_docset - gsed -i 's@HTML_EXTRA_STYLESHEET = docs/mylayout.css@HTML_EXTRA_STYLESHEET = docs/mylayout_docset.css@' Doxyfile_docset - rm -fr html *.docset - doxygen Doxyfile_docset - gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html - gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html - make -C html - mv html/*.docset . - gsed -i 's@doxygen@json@' me.nlohmann.json.docset/Contents/Info.plist - rm -fr Doxyfile_docset html +# call cppcheck on the main header file +cppcheck: + cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp -# update online documentation -update_doxygen_online: - make re2c pretty doxygen - rm -fr /tmp/github-html - cp -r html /tmp/github-html - git checkout gh-pages - rm -fr html - mv /tmp/github-html html - -cd html ; git rm $(shell git ls-files --deleted) - git add html - git commit -m "Doxygen update" - git checkout master + +########################################################################## +# maintainer targets +########################################################################## # create scanner with re2c re2c: src/json.hpp.re2c $(RE2C) -b -s -i --no-generation-date $< | $(SED) '1d' > src/json.hpp -# static analyser -cppcheck: - cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp - # pretty printer pretty: astyle --style=allman --indent=spaces=4 --indent-modifiers \ @@ -71,9 +48,10 @@ pretty: --lineend=linux --preserve-date --suffix=none \ src/json.hpp src/json.hpp.re2c test/unit.cpp benchmarks/benchmarks.cpp docs/examples/*.cpp -# update docs -update_docs: - make create -C docs/examples + +########################################################################## +# benchmarks +########################################################################## # benchmarks json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp diff --git a/Doxyfile b/doc/Doxyfile similarity index 98% rename from Doxyfile rename to doc/Doxyfile index b5e65a7e8..467f0c3e3 100644 --- a/Doxyfile +++ b/doc/Doxyfile @@ -28,7 +28,7 @@ INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = YES TAB_SIZE = 4 ALIASES = "complexity=@par Complexity\n" -ALIASES += liveexample{2}="@par Example\n \1 \n @includelineno \2.cpp \n Output:\n @verbinclude \2.output \n The example code above can be translated with @verbatim g++ -std=c++11 -Isrc docs/examples/\2.cpp -o \2 @endverbatim." +ALIASES += liveexample{2}="@par Example\n \1 \n @includelineno \2.cpp \n Output:\n @verbinclude \2.output \n The example code above can be translated with @verbatim g++ -std=c++11 -Isrc doc/examples/\2.cpp -o \2 @endverbatim." ALIASES += requirement="@par Requirements\n" TCL_SUBST = OPTIMIZE_OUTPUT_FOR_C = NO @@ -101,7 +101,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = src/json.hpp docs/doxyindex.cpp +INPUT = ../src/json.hpp doxyindex.cpp INPUT_ENCODING = UTF-8 FILE_PATTERNS = RECURSIVE = NO @@ -109,10 +109,10 @@ EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = nlohmann::internals -EXAMPLE_PATH = docs/examples +EXAMPLE_PATH = examples EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO -IMAGE_PATH = docs/images +IMAGE_PATH = images INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO @@ -145,7 +145,7 @@ HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = HTML_STYLESHEET = -HTML_EXTRA_STYLESHEET = docs/mylayout.css +HTML_EXTRA_STYLESHEET = css/mylayout.css HTML_EXTRA_FILES = HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 000000000..7fda8500b --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,64 @@ +SRCDIR = ../src + +clean: + rm -fr me.nlohmann.json.docset html + + +########################################################################## +# example files +########################################################################## + +# where are the example cpp files +EXAMPLES = $(wildcard examples/*.cpp) + +# create output from a stand-alone example file +%.output: %.cpp + make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" + ./$(<:.cpp=) > $@ + rm $(<:.cpp=) + +# compare created output with current output of the example files +%.test: %.cpp + make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" + ./$(<:.cpp=) > $@ + diff $@ $(<:.cpp=.output) + rm $(<:.cpp=) $@ + +# create output from all stand-alone example files +create_output: $(EXAMPLES:.cpp=.output) + +# check output of all stand-alone example files +check_output: $(EXAMPLES:.cpp=.test) + + +########################################################################## +# Doxygen HTML documentation +########################################################################## + +# create Doxygen documentation +doxygen: create_output + doxygen + gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html + gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html + + +########################################################################## +# docset +########################################################################## + +# create docset for Dash +docset: create_output + cp Doxyfile Doxyfile_docset + gsed -i 's/DISABLE_INDEX = NO/DISABLE_INDEX = YES/' Doxyfile_docset + gsed -i 's/SEARCHENGINE = YES/SEARCHENGINE = NO/' Doxyfile_docset + gsed -i 's/GENERATE_TREEVIEW = YES/GENERATE_TREEVIEW = NO/' Doxyfile_docset + gsed -i 's/BINARY_TOC = YES/BINARY_TOC = NO/' Doxyfile_docset + gsed -i 's@HTML_EXTRA_STYLESHEET = css/mylayout.css@HTML_EXTRA_STYLESHEET = css/mylayout_docset.css@' Doxyfile_docset + rm -fr html *.docset + doxygen Doxyfile_docset + gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html + gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html + make -C html + mv html/*.docset . + gsed -i 's@doxygen@json@' me.nlohmann.json.docset/Contents/Info.plist + rm -fr Doxyfile_docset html diff --git a/docs/mylayout.css b/doc/css/mylayout.css similarity index 100% rename from docs/mylayout.css rename to doc/css/mylayout.css diff --git a/docs/mylayout_docset.css b/doc/css/mylayout_docset.css similarity index 100% rename from docs/mylayout_docset.css rename to doc/css/mylayout_docset.css diff --git a/docs/doxyindex.cpp b/doc/doxyindex.cpp similarity index 100% rename from docs/doxyindex.cpp rename to doc/doxyindex.cpp diff --git a/docs/examples/array.cpp b/doc/examples/array.cpp similarity index 100% rename from docs/examples/array.cpp rename to doc/examples/array.cpp diff --git a/docs/examples/array.output b/doc/examples/array.output similarity index 100% rename from docs/examples/array.output rename to doc/examples/array.output diff --git a/docs/examples/back.cpp b/doc/examples/back.cpp similarity index 100% rename from docs/examples/back.cpp rename to doc/examples/back.cpp diff --git a/docs/examples/back.output b/doc/examples/back.output similarity index 100% rename from docs/examples/back.output rename to doc/examples/back.output diff --git a/docs/examples/basic_json.cpp b/doc/examples/basic_json.cpp similarity index 100% rename from docs/examples/basic_json.cpp rename to doc/examples/basic_json.cpp diff --git a/docs/examples/basic_json.output b/doc/examples/basic_json.output similarity index 100% rename from docs/examples/basic_json.output rename to doc/examples/basic_json.output diff --git a/docs/examples/basic_json__CompatibleArrayType.cpp b/doc/examples/basic_json__CompatibleArrayType.cpp similarity index 100% rename from docs/examples/basic_json__CompatibleArrayType.cpp rename to doc/examples/basic_json__CompatibleArrayType.cpp diff --git a/docs/examples/basic_json__CompatibleArrayType.output b/doc/examples/basic_json__CompatibleArrayType.output similarity index 100% rename from docs/examples/basic_json__CompatibleArrayType.output rename to doc/examples/basic_json__CompatibleArrayType.output diff --git a/docs/examples/basic_json__CompatibleObjectType.cpp b/doc/examples/basic_json__CompatibleObjectType.cpp similarity index 100% rename from docs/examples/basic_json__CompatibleObjectType.cpp rename to doc/examples/basic_json__CompatibleObjectType.cpp diff --git a/docs/examples/basic_json__CompatibleObjectType.output b/doc/examples/basic_json__CompatibleObjectType.output similarity index 100% rename from docs/examples/basic_json__CompatibleObjectType.output rename to doc/examples/basic_json__CompatibleObjectType.output diff --git a/docs/examples/basic_json__array_t.cpp b/doc/examples/basic_json__array_t.cpp similarity index 100% rename from docs/examples/basic_json__array_t.cpp rename to doc/examples/basic_json__array_t.cpp diff --git a/docs/examples/basic_json__array_t.output b/doc/examples/basic_json__array_t.output similarity index 100% rename from docs/examples/basic_json__array_t.output rename to doc/examples/basic_json__array_t.output diff --git a/docs/examples/basic_json__basic_json.cpp b/doc/examples/basic_json__basic_json.cpp similarity index 100% rename from docs/examples/basic_json__basic_json.cpp rename to doc/examples/basic_json__basic_json.cpp diff --git a/docs/examples/basic_json__basic_json.output b/doc/examples/basic_json__basic_json.output similarity index 100% rename from docs/examples/basic_json__basic_json.output rename to doc/examples/basic_json__basic_json.output diff --git a/docs/examples/basic_json__copyassignment.cpp b/doc/examples/basic_json__copyassignment.cpp similarity index 100% rename from docs/examples/basic_json__copyassignment.cpp rename to doc/examples/basic_json__copyassignment.cpp diff --git a/docs/examples/basic_json__copyassignment.output b/doc/examples/basic_json__copyassignment.output similarity index 100% rename from docs/examples/basic_json__copyassignment.output rename to doc/examples/basic_json__copyassignment.output diff --git a/docs/examples/basic_json__list_init_t.cpp b/doc/examples/basic_json__list_init_t.cpp similarity index 100% rename from docs/examples/basic_json__list_init_t.cpp rename to doc/examples/basic_json__list_init_t.cpp diff --git a/docs/examples/basic_json__list_init_t.output b/doc/examples/basic_json__list_init_t.output similarity index 100% rename from docs/examples/basic_json__list_init_t.output rename to doc/examples/basic_json__list_init_t.output diff --git a/docs/examples/basic_json__moveconstructor.cpp b/doc/examples/basic_json__moveconstructor.cpp similarity index 100% rename from docs/examples/basic_json__moveconstructor.cpp rename to doc/examples/basic_json__moveconstructor.cpp diff --git a/docs/examples/basic_json__moveconstructor.output b/doc/examples/basic_json__moveconstructor.output similarity index 100% rename from docs/examples/basic_json__moveconstructor.output rename to doc/examples/basic_json__moveconstructor.output diff --git a/docs/examples/basic_json__nullptr_t.cpp b/doc/examples/basic_json__nullptr_t.cpp similarity index 100% rename from docs/examples/basic_json__nullptr_t.cpp rename to doc/examples/basic_json__nullptr_t.cpp diff --git a/docs/examples/basic_json__nullptr_t.output b/doc/examples/basic_json__nullptr_t.output similarity index 100% rename from docs/examples/basic_json__nullptr_t.output rename to doc/examples/basic_json__nullptr_t.output diff --git a/docs/examples/basic_json__object_t.cpp b/doc/examples/basic_json__object_t.cpp similarity index 100% rename from docs/examples/basic_json__object_t.cpp rename to doc/examples/basic_json__object_t.cpp diff --git a/docs/examples/basic_json__object_t.output b/doc/examples/basic_json__object_t.output similarity index 100% rename from docs/examples/basic_json__object_t.output rename to doc/examples/basic_json__object_t.output diff --git a/docs/examples/basic_json__size_type_basic_json.cpp b/doc/examples/basic_json__size_type_basic_json.cpp similarity index 100% rename from docs/examples/basic_json__size_type_basic_json.cpp rename to doc/examples/basic_json__size_type_basic_json.cpp diff --git a/docs/examples/basic_json__size_type_basic_json.output b/doc/examples/basic_json__size_type_basic_json.output similarity index 100% rename from docs/examples/basic_json__size_type_basic_json.output rename to doc/examples/basic_json__size_type_basic_json.output diff --git a/docs/examples/basic_json__value_t.cpp b/doc/examples/basic_json__value_t.cpp similarity index 100% rename from docs/examples/basic_json__value_t.cpp rename to doc/examples/basic_json__value_t.cpp diff --git a/docs/examples/basic_json__value_t.output b/doc/examples/basic_json__value_t.output similarity index 100% rename from docs/examples/basic_json__value_t.output rename to doc/examples/basic_json__value_t.output diff --git a/docs/examples/begin.cpp b/doc/examples/begin.cpp similarity index 100% rename from docs/examples/begin.cpp rename to doc/examples/begin.cpp diff --git a/docs/examples/begin.output b/doc/examples/begin.output similarity index 100% rename from docs/examples/begin.output rename to doc/examples/begin.output diff --git a/docs/examples/cbegin.cpp b/doc/examples/cbegin.cpp similarity index 100% rename from docs/examples/cbegin.cpp rename to doc/examples/cbegin.cpp diff --git a/docs/examples/cbegin.output b/doc/examples/cbegin.output similarity index 100% rename from docs/examples/cbegin.output rename to doc/examples/cbegin.output diff --git a/docs/examples/cend.cpp b/doc/examples/cend.cpp similarity index 100% rename from docs/examples/cend.cpp rename to doc/examples/cend.cpp diff --git a/docs/examples/cend.output b/doc/examples/cend.output similarity index 100% rename from docs/examples/cend.output rename to doc/examples/cend.output diff --git a/docs/examples/clear.cpp b/doc/examples/clear.cpp similarity index 100% rename from docs/examples/clear.cpp rename to doc/examples/clear.cpp diff --git a/docs/examples/clear.output b/doc/examples/clear.output similarity index 100% rename from docs/examples/clear.output rename to doc/examples/clear.output diff --git a/docs/examples/crbegin.cpp b/doc/examples/crbegin.cpp similarity index 100% rename from docs/examples/crbegin.cpp rename to doc/examples/crbegin.cpp diff --git a/docs/examples/crbegin.output b/doc/examples/crbegin.output similarity index 100% rename from docs/examples/crbegin.output rename to doc/examples/crbegin.output diff --git a/docs/examples/crend.cpp b/doc/examples/crend.cpp similarity index 100% rename from docs/examples/crend.cpp rename to doc/examples/crend.cpp diff --git a/docs/examples/crend.output b/doc/examples/crend.output similarity index 100% rename from docs/examples/crend.output rename to doc/examples/crend.output diff --git a/docs/examples/dump.cpp b/doc/examples/dump.cpp similarity index 100% rename from docs/examples/dump.cpp rename to doc/examples/dump.cpp diff --git a/docs/examples/dump.output b/doc/examples/dump.output similarity index 100% rename from docs/examples/dump.output rename to doc/examples/dump.output diff --git a/docs/examples/empty.cpp b/doc/examples/empty.cpp similarity index 100% rename from docs/examples/empty.cpp rename to doc/examples/empty.cpp diff --git a/docs/examples/empty.output b/doc/examples/empty.output similarity index 100% rename from docs/examples/empty.output rename to doc/examples/empty.output diff --git a/docs/examples/end.cpp b/doc/examples/end.cpp similarity index 100% rename from docs/examples/end.cpp rename to doc/examples/end.cpp diff --git a/docs/examples/end.output b/doc/examples/end.output similarity index 100% rename from docs/examples/end.output rename to doc/examples/end.output diff --git a/docs/examples/front.cpp b/doc/examples/front.cpp similarity index 100% rename from docs/examples/front.cpp rename to doc/examples/front.cpp diff --git a/docs/examples/front.output b/doc/examples/front.output similarity index 100% rename from docs/examples/front.output rename to doc/examples/front.output diff --git a/docs/examples/is_array.cpp b/doc/examples/is_array.cpp similarity index 100% rename from docs/examples/is_array.cpp rename to doc/examples/is_array.cpp diff --git a/docs/examples/is_array.output b/doc/examples/is_array.output similarity index 100% rename from docs/examples/is_array.output rename to doc/examples/is_array.output diff --git a/docs/examples/is_boolean.cpp b/doc/examples/is_boolean.cpp similarity index 100% rename from docs/examples/is_boolean.cpp rename to doc/examples/is_boolean.cpp diff --git a/docs/examples/is_boolean.output b/doc/examples/is_boolean.output similarity index 100% rename from docs/examples/is_boolean.output rename to doc/examples/is_boolean.output diff --git a/docs/examples/is_null.cpp b/doc/examples/is_null.cpp similarity index 100% rename from docs/examples/is_null.cpp rename to doc/examples/is_null.cpp diff --git a/docs/examples/is_null.output b/doc/examples/is_null.output similarity index 100% rename from docs/examples/is_null.output rename to doc/examples/is_null.output diff --git a/docs/examples/is_number.cpp b/doc/examples/is_number.cpp similarity index 100% rename from docs/examples/is_number.cpp rename to doc/examples/is_number.cpp diff --git a/docs/examples/is_number.output b/doc/examples/is_number.output similarity index 100% rename from docs/examples/is_number.output rename to doc/examples/is_number.output diff --git a/docs/examples/is_number_float.cpp b/doc/examples/is_number_float.cpp similarity index 100% rename from docs/examples/is_number_float.cpp rename to doc/examples/is_number_float.cpp diff --git a/docs/examples/is_number_float.output b/doc/examples/is_number_float.output similarity index 100% rename from docs/examples/is_number_float.output rename to doc/examples/is_number_float.output diff --git a/docs/examples/is_number_integer.cpp b/doc/examples/is_number_integer.cpp similarity index 100% rename from docs/examples/is_number_integer.cpp rename to doc/examples/is_number_integer.cpp diff --git a/docs/examples/is_number_integer.output b/doc/examples/is_number_integer.output similarity index 100% rename from docs/examples/is_number_integer.output rename to doc/examples/is_number_integer.output diff --git a/docs/examples/is_object.cpp b/doc/examples/is_object.cpp similarity index 100% rename from docs/examples/is_object.cpp rename to doc/examples/is_object.cpp diff --git a/docs/examples/is_object.output b/doc/examples/is_object.output similarity index 100% rename from docs/examples/is_object.output rename to doc/examples/is_object.output diff --git a/docs/examples/is_string.cpp b/doc/examples/is_string.cpp similarity index 100% rename from docs/examples/is_string.cpp rename to doc/examples/is_string.cpp diff --git a/docs/examples/is_string.output b/doc/examples/is_string.output similarity index 100% rename from docs/examples/is_string.output rename to doc/examples/is_string.output diff --git a/docs/examples/max_size.cpp b/doc/examples/max_size.cpp similarity index 100% rename from docs/examples/max_size.cpp rename to doc/examples/max_size.cpp diff --git a/docs/examples/max_size.output b/doc/examples/max_size.output similarity index 100% rename from docs/examples/max_size.output rename to doc/examples/max_size.output diff --git a/docs/examples/object.cpp b/doc/examples/object.cpp similarity index 100% rename from docs/examples/object.cpp rename to doc/examples/object.cpp diff --git a/docs/examples/object.output b/doc/examples/object.output similarity index 100% rename from docs/examples/object.output rename to doc/examples/object.output diff --git a/docs/examples/rbegin.cpp b/doc/examples/rbegin.cpp similarity index 100% rename from docs/examples/rbegin.cpp rename to doc/examples/rbegin.cpp diff --git a/docs/examples/rbegin.output b/doc/examples/rbegin.output similarity index 100% rename from docs/examples/rbegin.output rename to doc/examples/rbegin.output diff --git a/docs/examples/rend.cpp b/doc/examples/rend.cpp similarity index 100% rename from docs/examples/rend.cpp rename to doc/examples/rend.cpp diff --git a/docs/examples/rend.output b/doc/examples/rend.output similarity index 100% rename from docs/examples/rend.output rename to doc/examples/rend.output diff --git a/docs/examples/size.cpp b/doc/examples/size.cpp similarity index 100% rename from docs/examples/size.cpp rename to doc/examples/size.cpp diff --git a/docs/examples/size.output b/doc/examples/size.output similarity index 100% rename from docs/examples/size.output rename to doc/examples/size.output diff --git a/doc/git-update-ghpages b/doc/git-update-ghpages new file mode 100755 index 000000000..f9760fee6 --- /dev/null +++ b/doc/git-update-ghpages @@ -0,0 +1,221 @@ +#!/usr/bin/env ruby +# git update-ghpages user/repo -b gh-pages -p manual/ -i + +require 'fileutils' +require 'tmpdir' + +module Params + def extract(what) i = index(what) and slice!(i, 2)[1] end; + def first_is(what) shift if what.include?(self.first); end + def self.[](*what) what.extend Params; end + def ===(argv) argv.first_is(self); end +end + +# ============================================================================ + +ARGV.extend Params + +class CLI + # CLI options + attr_reader :prefix #=> "doc/" + attr_reader :input #=> "/home/me/projects/foo" + attr_reader :message #=> "Updated" + attr_reader :repo #=> "git@github.com:me/project.git" + attr_reader :url #=> "http://me.github.com/project" + attr_reader :branch #=> "gh-pages" + + def verbose?() @verbose; end + def force?() @force; end + def simulate?() @simulate; end + + def initialize + # Switches + @verbose = !! (ARGV.extract('--verbose') || ARGV.delete('-v')) + @simulate = !! (ARGV.extract('--simulate') || ARGV.delete('-s')) + @force = !! (ARGV.delete('--force') || ARGV.delete('-f')) + + # Stuff + @prefix = ARGV.extract('--prefix') || ARGV.extract('-p') || '' + @input = File.expand_path(ARGV.extract('--input') || ARGV.extract('-i') || '.') + @message = ARGV.extract('--message') || ARGV.extract('-m') || 'Update' + + # Github info + branch = ARGV.extract('--branch') || ARGV.extract('-b') || nil + @repo, @url, @branch = get_github_info(ARGV.shift, branch) + end + + def git_current_branch + `git rev-parse --abbrev-ref HEAD`.strip + end + + def git_deploy + in_temp_path do |temppath| + status "Cloning repository" + system! "git clone #{repo} -b #{branch} #{temppath}" + + if git_current_branch != branch + status "Warning: No #{branch} branch found in repo, creating one." + return git_deploy_force + end + + copy_files input, File.join(temppath, prefix) + + status "Committing files" + system! "git add .; git add -u; git commit -m #{message.to_s.inspect}" + + unless simulate? + status "Updating repo" + system! "git push origin #{branch}" + end + true + end + end + + def git_deploy_force + in_temp_path do |temppath| + status "Creating new repository" + system! "git init ." + system! "git checkout -b gh-pages" + + copy_files input, File.join(temppath, prefix) + + status "Committing files" + system! "git add . && git commit -m #{message.to_s.inspect}" + + unless simulate? + status "Updating repo" + system! "git push #{repo} gh-pages:#{branch} --force" + end + true + end + end + + def get_github_info(repo, branch=nil, prefix=nil) + if github_format?(repo) + user, repo_name = repo.split('/') + r = "git@github.com:#{repo}.git" + + # User page or project page? + if repo_name =~ /\.github\.com/ + [r, "http://#{repo_name}/#{prefix}", branch || 'master' ] + else + [r, "http://#{user}.github.com/#{repo_name}/#{prefix}", branch || 'gh-pages' ] + end + else + [repo, nil, branch] + end + end + + def run! + unless repo + print_help + exit 128 + end + + status "Deploying to #{repo} (branch #{branch})" + msg "NOTE: Running in simulation mode." if simulate? + msg "WARNING: If the repository has gh-pages history, it with be overriden." if force? && !simulate? + + result = force? ? git_deploy_force : git_deploy + + if result + puts "" + status "Done." + msg "See: #{url}" if url && !simulate? + else + tip "Failed." + exit 1 + end + end + + def status(str) + puts "#{c('===>',34)} #{c(str, 32)}" + end + + def msg(str) + puts " #{c(str, 32)}" + end + + def c(str, color) + "\033[#{color}m#{str}\033[0m" + end + + def print_help + tip \ + %{Usage: git update-ghpages username/repository [options] + + Flags: + -f, --force Force an update (WARNING: kills the history!) + -s, --simulate Creates the repository, but doesn't push. + -v, --verbose Verbose mode + + Options: + -p PATH, --prefix The prefix + -i PATH, --input Input (defaults to current directory) + -b BRANCH, --branch The branch to deploy to (defaults to gh-pages) + -m MSG, --message Commit message (defaults to 'Update') + + Examples: + + Update the repo 'coffee' of github user 'james' with the files from the + current directory. The files will be in http://james.github.com/coffee. + + $ git update-ghpages james/coffee + + Same as above, but take the files from 'doc/'. + + $ git update-ghpages james/coffee -i doc + + Same as the first, but the files will instead be in + http://james.github.com/coffee/manual. + + $ git update-ghpages james/coffee -i doc -p manual + }.gsub(/^ {4}/, '') + end + +private # Helpers + + def tip(msg) + $stderr.write "#{msg}\n" + end + + def github_format?(str) + str =~ /^([A-Za-z0-9\-_]+)\/([A-Za-z0-9\-_\.]+)$/ + end + + # Performs actions inside a temp path. + def in_temp_path(&blk) + require 'tmpdir' + Dir.mktmpdir do |dir| + Dir.chdir(dir) { yield dir } + end + end + + def system!(str) + puts `#{str} 2>&1`.strip.gsub(/^/, " ") + raise "Failed with exit code #{$?.to_i}" unless $?.to_i == 0 + end + + # Returns the current branch name + def git_branch + `git symbolic-ref HEAD`.strip.split('/').last + end + + # Copy files from source folder to another + def copy_files(from, to) + status "Copying files #{from} => #{to}..." if verbose? + + Dir["#{from}/**/*"].each do |f| + next unless File.file?(f) + + target = File.join(to, f.gsub(/^#{Regexp.escape from}/, '')) + + FileUtils.mkdir_p File.dirname(target) + msg "%20s => %-20s" % [f, target] if verbose? + FileUtils.cp f, target + end + end + +end + +CLI.new.run! diff --git a/docs/images/range-begin-end.svg b/doc/images/range-begin-end.svg similarity index 100% rename from docs/images/range-begin-end.svg rename to doc/images/range-begin-end.svg diff --git a/docs/images/range-rbegin-rend.svg b/doc/images/range-rbegin-rend.svg similarity index 100% rename from docs/images/range-rbegin-rend.svg rename to doc/images/range-rbegin-rend.svg diff --git a/docs/begin.md b/docs/begin.md deleted file mode 100644 index 3730402d1..000000000 --- a/docs/begin.md +++ /dev/null @@ -1,41 +0,0 @@ -```cpp -iterator begin(); -const_iterator begin() const; -const_iterator cbegin() const; -``` - -## Description - -Returns an iterator to the first value in the JSON container. If the JSON container is empty, the returned iterator will be equal to [`end()`](https://github.com/nlohmann/json/wiki/nlohmann::basicjson::end). - -![illustration of iterators](http://upload.cppreference.com/mwiki/images/1/1b/range-begin-end.svg) - -## Parameters - -None. - -## Return value - -Iterator to the first value. Note the return value its deferencabilty depends on the different value types: - -| value type | deferenceable | description | -| ---------- | ------------- | ----------- | -| null | no | `null` has no value, always equal to [`end()`](https://github.com/nlohmann/json/wiki/nlohmann::basicjson::end) | -| boolean | yes | iterator to the boolean value | -| string | yes | iterator to the string value | -| number | yes | iterator to the number value | -| object | only if object is not empty | iterator to the begin of the object | -| array | only if array is not empty | iterator to the begin of the array | - -## Complexity - -Constant, as long as `ArrayType` and `ObjectType` satisfy the [Container concept](http://en.cppreference.com/w/cpp/concept/Container). - -## Exceptions - -None. The function's noexcept-specification is `noexcept`. - -## See also - -- [**end**, **cend**](https://github.com/nlohmann/json/wiki/nlohmann::basicjson::end)
- returns an iterator to the end diff --git a/docs/empty.md b/docs/empty.md deleted file mode 100644 index 62f269bee..000000000 --- a/docs/empty.md +++ /dev/null @@ -1,55 +0,0 @@ -# nlohmann::basic_json::empty - -```cpp -bool empty() const noexcept; -``` - -Checks if the container has no elements; that is, whether `begin() == end()`. - -## Parameters - -(none) - -## Return value - -`true` if the container is empty, `false` otherwise. Note that the JSON types string, number, and boolean are never empty, null values are always empty. - -## Exceptions - -`noexcept` specification: `noexcept`. - -## Complexity - -Constant (assuming types `ObjectType` and `ArrayType` satisfy the [Container](http://en.cppreference.com/w/cpp/concept/Container) concept). - -## Example - -The following code uses empty to check if a `json` container contains any elements: - -```cpp -#include -#include - -int main() -{ - nlohman::json numbers; - std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; - - numbers.push_back(42); - numbers.push_back(13317); - std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; -} -``` - -### Output - - Initially, numbers.empty(): 1 - After adding elements, numbers.empty(): 0 - -## Requirements - -The `empty` member function is part of the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirement. - -## See also - -- `size()` diff --git a/docs/examples/Makefile b/docs/examples/Makefile deleted file mode 100644 index 71182ee3f..000000000 --- a/docs/examples/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -SRCDIR = ../../src - -EXAMPLES = $(wildcard *.cpp) - -all: - @echo "check" - @echo "create" - -clean: - rm -f $(EXAMPLES:.cpp=) $(EXAMPLES:.cpp=.output) $(EXAMPLES:.cpp=.test) - -%.output: %.cpp - make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" - ./$(<:.cpp=) > $@ - rm $(<:.cpp=) - -%.test: %.cpp - make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" - ./$(<:.cpp=) > $@ - diff $@ $(<:.cpp=.output) - rm $(<:.cpp=) $@ - -create: $(EXAMPLES:.cpp=.output) - -check: $(EXAMPLES:.cpp=.test) diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index e824bd051..000000000 --- a/docs/index.md +++ /dev/null @@ -1,143 +0,0 @@ -# nlohmann::basic_json - -Defined in header `` - -```cpp -template < - template class ObjectType = std::map, - template class ArrayType = std::vector, - class StringType = std::string, - class BooleanType = bool, - class NumberIntegerType = int64_t, - class NumberFloatType = double, - template class Allocator = std::allocator -> class basic_json; -``` - -## Template Parameters - -- `ObjectType` - The type to store collection of name/value pairs. It can be any associative container that can hold key-value pairs as long as the key type is the same as `StringType`. The value type is again `nlohmann::basic_json`. The parameter `ObjectType` defaults to [`std::map`](http://en.cppreference.com/w/cpp/container/map). -- `ArrayType` - The type to store ordered value lists. It can be any sequence container. The parameter `ArrayType` defaults to a [`std::vector`](http://en.cppreference.com/w/cpp/container/vector) whose elements are of type `nlohmann::basic_json`. -- `StringType` - The type to store string values. The parameter `StringType` defaults to [`std::string`](http://en.cppreference.com/w/cpp/string/basic_string). -- `BooleanType` -- `NumberIntegerType` -- `NumberFloatType` -- `Allocator` - An allocator that is used to acquire memory to store the elements. The type must meet the requirements of [`Allocator`](http://en.cppreference.com/w/cpp/concept/Allocator). - -## Specializations - -A standard JSON type `nlohmann::json` is defined in `` which uses the default types: - -```cpp -using json = basic_json< - std::map, - std::vector, - std::string, - bool, - int64_t, - double, - std::allocator -> -``` - - -## Iterator invalidation - -## Member types - -- `value_type` -- `reference` -- `const_reference` -- `difference_type` -- `size_type` -- `allocator_type` -- `pointer` -- `const_pointer` -- `iterator` -- `const_iterator` -- `reverse_iterator` -- `const_reverse_iterator` -- `object_t` -- `array_t` -- `string_t` -- `boolean_t` -- `number_integer_t` -- `number_float_t` -- `list_init_t` -- `json_value` - -## Member functions - -- constructor -- destructor -- `operator=` -- `get_allocator` - -### Object inspection - -- `dump` -- `type` -- `is_null` -- `is_boolean` -- `is_number` -- `is_object` -- `is_array` -- `is_string` -- `operator value_t` -- `std::hash` - -### Value conversion - -- `get` -- implicit conversion - -### Element access - -- `at` -- `operator[]` -- `erase` -- `find` -- `count` - -### Iterators - -- `begin` / `cbegin` -- `end` / `cend` -- `rbegin` / `crbegin` -- `rend` / `crend` - -### Capacity - -- [`empty`](empty) -- `size` -- `max_size` - -### Modifiers - -- `clear` -- `push_back` -- `operator+=` -- `erase` -- `swap` -- `std::swap` - -### Comparisons - -- `operator==` -- `operator!=` -- `operator<` -- `operator<=` -- `operator>` -- `operator>=` - -### Serialization - -- `dump` -- `operator<<` -- `operator>>` - -### Deserialization - -- `parse` -- `operator<<` -- `operator>>` diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100644 index 29eba859e..000000000 --- a/mkdocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -site_name: JSON for Modern C++ - -theme: readthedocs -#theme: bootstrap -#theme: yeti - -markdown_extensions: [fenced_code]