From a478af2a27e973d03e07ef98e38986c6aa0e2857 Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 24 Apr 2015 14:47:12 +0200 Subject: [PATCH] more documentation --- README.md | 52 ++++++++++++++++++++++++++++++++++------- include/mstch/mstch.hpp | 4 ++-- test/benchmark_main.cpp | 2 +- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8a2efa1..4f68f47 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ![mstch logo](http://i.imgur.com/XAdHwUs.png) -mstch is a complete implementation of [{{mustache}}](http://mustache.github.io/) templates using modern C++. +mstch is a complete implementation of [{{mustache}}](http://mustache.github.io/) +templates using modern C++. [![Build Status](https://travis-ci.org/no1msd/mstch.svg?branch=master)](https://travis-ci.org/no1msd/mstch) @@ -48,11 +49,45 @@ Hi Mark! Hi Scott! ``` +### Data structure + +The types in the example above, `mstch::array` and `mstch::map` are actually +aliases for standard types: + +```c++ +using map = std::map; +using array = std::vector; +``` + +`mstch::node` is a `boost::variant` that can hold a `std::string`, `int`, +`bool`, lambda expression or a `std::shared_ptr` to a `mstch::object` +(see below), also a map or an array recursively. Essentially it works just like +a JSON object. + +Note that when using a `std::string` as value you must explicitly specify the +type, since a `const char*` literal like `"foobar"` would be implicitly +converted to bool. Alternatively you can use [C++14 string_literals](http://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s) +if your compiler supports it. + +## Advanced usage + +### Partials + +TODO + +### Lambdas + +TODO + +### Objects + +TODO + ## Requirements - A C++ compiler with decent C++11 support. Currently only tested with GCC 4.9. - - Boost 1.54 - - CMake for building + - Boost 1.54+ for [Boost.Variant](http://www.boost.org/doc/libs/1_57_0/doc/html/variant.html) + - CMake 2.8+ for building ## Installing @@ -66,7 +101,12 @@ From the root of the source tree: $ make install ``` -### Running the unit tests +## Running the unit tests + +Unit tests are using the [Catch](https://github.com/philsquared/Catch) framework, +included in the repository. [Boost.Program_Options](http://www.boost.org/doc/libs/1_58_0/doc/html/program_options.html) +and [The Boost Algorithm Library](http://www.boost.org/doc/libs/1_57_0/libs/algorithm/doc/html/index.html) +are also required to build them. ```bash $ mkdir build @@ -75,7 +115,3 @@ From the root of the source tree: $ make $ make test ``` - -## Advanced usage - -TODO \ No newline at end of file diff --git a/include/mstch/mstch.hpp b/include/mstch/mstch.hpp index 9cb10c9..2679488 100644 --- a/include/mstch/mstch.hpp +++ b/include/mstch/mstch.hpp @@ -64,10 +64,10 @@ class lambda { using node = boost::make_recursive_variant< boost::blank, std::string, int, bool, lambda, std::shared_ptr>, - std::map, + std::map, std::vector>::type; using object = internal::object_t; -using map = std::map; +using map = std::map; using array = std::vector; std::string render( diff --git a/test/benchmark_main.cpp b/test/benchmark_main.cpp index 42007c9..82f7adb 100644 --- a/test/benchmark_main.cpp +++ b/test/benchmark_main.cpp @@ -27,7 +27,7 @@ int main() { std::vector times; for (int j = 0; j < 10; j++) { - unsigned long start = current_msec(); + auto start = current_msec(); for (int i = 0; i < 5000; i++) mstch::render(comment_tmp, comment_view); times.push_back(current_msec() - start);