├── .gitattributes ├── .gitignore ├── dnn_serialize.sln ├── dnn_serialize.vcxproj ├── docs ├── Doxyfile ├── Doxyfile.in ├── Makefile ├── conf.py ├── developer_guides │ ├── Adding-a-new-layer.md │ ├── How-to-contribute.md │ └── index.rst ├── device-abstraction-uml.puml ├── getting_started │ ├── Getting-started.md │ └── index.rst ├── how_tos │ ├── How-Tos.md │ ├── Integrate-with-your-application.md │ ├── Train-network-with-your-dataset.md │ └── index.rst ├── index.rst ├── make.bat ├── readme.md ├── resource │ └── graph.gif └── update_log │ ├── index.rst │ └── v0_0_1-to-v0_1_0.md ├── readme.md ├── test.cpp └── third_party └── cereal ├── access.hpp ├── archives ├── adapters.hpp ├── binary.hpp ├── json.hpp ├── portable_binary.hpp └── xml.hpp ├── cereal.hpp ├── details ├── helpers.hpp ├── polymorphic_impl.hpp ├── polymorphic_impl_fwd.hpp ├── static_object.hpp ├── traits.hpp └── util.hpp ├── external ├── base64.hpp ├── rapidjson │ ├── allocators.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ │ ├── en.h │ │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── fwd.h │ ├── internal │ │ ├── biginteger.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ ├── istreamwrapper.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ ├── ostreamwrapper.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── schema.h │ ├── stream.h │ ├── stringbuffer.h │ └── writer.h └── rapidxml │ ├── license.txt │ ├── manual.html │ ├── rapidxml.hpp │ ├── rapidxml_iterators.hpp │ ├── rapidxml_print.hpp │ └── rapidxml_utils.hpp ├── macros.hpp └── types ├── array.hpp ├── base_class.hpp ├── bitset.hpp ├── boost_variant.hpp ├── chrono.hpp ├── common.hpp ├── complex.hpp ├── concepts └── pair_associative_container.hpp ├── deque.hpp ├── forward_list.hpp ├── functional.hpp ├── list.hpp ├── map.hpp ├── memory.hpp ├── polymorphic.hpp ├── queue.hpp ├── set.hpp ├── stack.hpp ├── string.hpp ├── tuple.hpp ├── unordered_map.hpp ├── unordered_set.hpp ├── utility.hpp ├── valarray.hpp └── vector.hpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | .tlog 50 | .log 51 | Debug 52 | Release 53 | .suo 54 | *.db 55 | *.opendb 56 | *.filters 57 | 58 | docs/_build -------------------------------------------------------------------------------- /dnn_serialize.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dnn_serialize", "dnn_serialize.vcxproj", "{8B7D45B8-A50B-47C4-AF9B-66121FA64E13}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Debug|x64.ActiveCfg = Debug|x64 17 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Debug|x64.Build.0 = Debug|x64 18 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Debug|x86.ActiveCfg = Debug|Win32 19 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Debug|x86.Build.0 = Debug|Win32 20 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Release|x64.ActiveCfg = Release|x64 21 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Release|x64.Build.0 = Release|x64 22 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Release|x86.ActiveCfg = Release|Win32 23 | {8B7D45B8-A50B-47C4-AF9B-66121FA64E13}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /docs/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = @PROJECT_NAME@ 2 | PROJECT_NUMBER = @PROJECT_VERSION@ 3 | PROJECT_BRIEF = "A header only, dependency-free deep learning framework in C++11" 4 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \ 5 | @PROJECT_BINARY_DIR@ 6 | OUTPUT_LANGUAGE = English 7 | INPUT = @CMAKE_SOURCE_DIR@/tiny_cnn \ 8 | @CMAKE_SOURCE_DIR@/examples \ 9 | @CMAKE_SOURCE_DIR@/doc 10 | FILE_PATTERNS = *.h *.md 11 | RECURSIVE = YES 12 | IMAGE_PATH = @CMAKE_SOURCE_DIR@/doc 13 | USE_MDFILE_AS_MAINPAGE = @CMAKE_SOURCE_DIR@/doc/readme.md 14 | JAVADOC_AUTOBRIEF = YES 15 | GENERATE_HTML = YES 16 | GENERATE_LATEX = NO 17 | OUTPUT_DIRECTORY = @CMAKE_BINARY_DIR@/doc 18 | EXCLUDE_PATTERNS = */caffe.pb.h 19 | -------------------------------------------------------------------------------- /docs/developer_guides/Adding-a-new-layer.md: -------------------------------------------------------------------------------- 1 | # Adding a new layer 2 | This section describes how to create a new layer incorporated with tiny-dnn. Let's create simple fully-connected layer for example. 3 | 4 | > Note: This document is old, and doesn't fit to current tiny-dnn. We need to update. 5 | 6 | ### Declare class 7 | Let's define your layer. All of layer operations in tiny-dnn are derived from ```layer``` class. 8 | 9 | ```cpp 10 | // calculate y = Wx + b 11 | class fully_connected : public layer { 12 | public: 13 | //todo 14 | }; 15 | 16 | ``` 17 | 18 | the ```layer``` class prepares input/output data for your calculation. To do this, you must tell ```layer```'s constructor what you need. 19 | 20 | ```cpp 21 | layer::layer(const std::vector& in_type, 22 | const std::vector& out_type) 23 | ``` 24 | 25 | For example, consider calculating fully-connected operation: ```y = Wx + b```. In this caluculation, Input (right hand of this eq) is data ```x```, weight ```W``` and bias ```b```. Output is, of course ```y```. So it's constructor should pass {data,weight,bias} as input and {data} as output. 26 | 27 | ```cpp 28 | // calculate y = Wx + b 29 | class fully_connected : public layer { 30 | public: 31 | fully_connected(size_t x_size, size_t y_size) 32 | :layer({vector_type::data,vector_type::weight,vector_type::bias}, // x, W and b 33 | {vector_type::data}), 34 | x_size_(x_size), 35 | y_size_(y_size) 36 | {} 37 | 38 | private: 39 | size_t x_size_; // number of input elements 40 | size_t y_size_; // number of output elements 41 | }; 42 | 43 | ``` 44 | 45 | the ```vector_type::data``` is some input data passed by previous layer, or output data consumed by next layer. ```vector_type::weight``` and ```vector_type::bias``` represents trainable parameters. The only difference between them is default initialization method: ```weight``` is initialized by random value, and ```bias``` is initialized by zero-vector (this behaviour can be changed by network::weight_init method). If you need another vector to calculate, ```vector_type::aux``` can be used. 46 | 47 | ### Implement virtual method 48 | There are 5 methods to implement. In most case 3 methods are written as one-liner and remaining 2 are essential: 49 | 50 | - layer_type 51 | - in_shape 52 | - out_shape 53 | - forward_propagation 54 | - back_propagation 55 | 56 | ##### layer_type 57 | Returns name of your layer. 58 | 59 | ```cpp 60 | std::string layer_type() const override { 61 | return "fully-connected"; 62 | } 63 | ``` 64 | 65 | ##### in_shape/out_shape 66 | Returns input/output shapes corresponding to inputs/outputs. Shapes is defined by [width, height, depth]. For example fully-connected layer treats input data as 1-dimensional array, so its shape is [N, 1, 1]. 67 | 68 | ```cpp 69 | std::vector in_shape() const override { 70 | // return input shapes 71 | // order of shapes must be equal to argument of layer constructor 72 | return { shape3d(x_size_, 1, 1), // x 73 | shape3d(x_size_, y_size_, 1), // W 74 | shape3d(y_size_, 1, 1) }; // b 75 | } 76 | 77 | std::vector out_shape() const override { 78 | return { shape3d(y_size_, 1, 1) }; // y 79 | } 80 | ``` 81 | 82 | #### forward_propagation 83 | Execute forward calculation in this method. 84 | 85 | ```cpp 86 | void forward_propagation(cnn_size_t worker_index, 87 | const std::vector& in_data, 88 | std::vector& out_data) override { 89 | const vec_t& x = *in_data[0]; // it's size is in_shapes()[0] (=[x_size_,1,1]) 90 | const vec_t& W = *in_data[1]; 91 | const vec_t& b = *in_data[2]; 92 | vec_t& y = *out_data[0]; 93 | 94 | std::fill(y.begin(), y.end(), 0.0); 95 | 96 | // y = Wx+b 97 | for (size_t r = 0; r < y_size_; r++) { 98 | for (size_t c = 0; c < x_size_; c++) 99 | y[r] += W[r*x_size_+c]*x[c]; 100 | y[r] += b[r]; 101 | } 102 | } 103 | ``` 104 | 105 | the ```in_data/out_data``` is array of input/output data, which is ordered as you told ```layer```'s constructor. The implementation is simple and straightforward, isn't it? 106 | 107 | ```worker_index``` is task-id. It is always zero if you run tiny-dnn in single thread. If some class member variables are updated while forward/backward pass, these members must be treated carefully to avoid data race. If their variables are task-independent, your class can hold just N variables and access them by worker_index (you can see this example in [max_pooling_layer.h](../tiny_cnn/layers/max_pooling_layer.h)). 108 | input/output data managed by ```layer``` base class is *task-local*, so ```in_data/out_data``` is treated as if it is running on single thread. 109 | 110 | #### back propagation 111 | 112 | ```cpp 113 | void back_propagation(cnn_size_t index, 114 | const std::vector& in_data, 115 | const std::vector& out_data, 116 | std::vector& out_grad, 117 | std::vector& in_grad) override { 118 | const vec_t& curr_delta = *out_grad[0]; // dE/dy (already calculated in next layer) 119 | const vec_t& x = *in_data[0]; 120 | const vec_t& W = *in_data[1]; 121 | vec_t& prev_delta = *in_grad[0]; // dE/dx (passed into previous layer) 122 | vec_t& dW = *in_grad[1]; // dE/dW 123 | vec_t& db = *in_grad[2]; // dE/db 124 | 125 | // propagate delta to prev-layer 126 | for (size_t c = 0; c < x_size_; c++) 127 | for (size_t r = 0; r < y_size_; r++) 128 | prev_delta[c] += curr_delta[r] * W[r*x_size_+c]; 129 | 130 | // accumulate weight difference 131 | for (size_t r = 0; r < y_size_; r++) 132 | for (size_t c = 0; c < x_size_; c++) 133 | dW[r*x_size_+c] += curr_delta[r] * x[c]; 134 | 135 | // accumulate bias difference 136 | for (size_t r = 0; r < y_size_; r++) 137 | db[r] += curr_delta[r]; 138 | } 139 | ``` 140 | 141 | the ```in_data/out_data``` are just same as forward_propagation, and ```in_grad/out_grad``` are its gradient. Order of gradient values are same as ```in_data/out_data```. 142 | 143 | > Note: Gradient of weight/bias are collected over mini-batch and zero-cleared automatically, so you can't use assignment operator to these elements (layer will forget previous training data in mini-batch!). like this example, use ```operator += ``` instead. Gradient of data (```prev_delta``` in the example) may already have meaningful values if two or more layers share this data, so you can't overwrite this value too. 144 | 145 | ### Verify backward caluculation 146 | It is always a good idea to check if your backward implementation is correct. ```network``` class provides ```gradient_check``` method for this purpose. 147 | Let's add following lines to test/test_network.h and execute test. 148 | ``` 149 | TEST(network, gradient_check_fully_connected) { 150 | network net; 151 | net << fully_connected(2, 3) 152 | << fully_connected(3, 2); 153 | 154 | std::vector in{ tensor_t{ 1, { 0.5, 1.0 } } }; 155 | std::vector> t = { std::vector(1, {1}) }; 156 | 157 | EXPECT_TRUE(net.gradient_check(in, t, 1e-4, GRAD_CHECK_ALL)); 158 | } 159 | ``` 160 | 161 | Congratulations! Now you can use this new class as a tiny-dnn layer. 162 | -------------------------------------------------------------------------------- /docs/developer_guides/How-to-contribute.md: -------------------------------------------------------------------------------- 1 | How to contribute 2 | ======== 3 | 4 | Thanks for taking the time to contribute to tiny-dnn! The following is a few guidelines for contributors. 5 | These are just guidelines, not rules, and feel free to propose changes to this document in a pull request. 6 | 7 | ## Getting Started 8 | - Make sure you have a C++11 compiler. 9 | - Make sure you have a GitHub account. 10 | - Register a report about your issue. 11 | - Check [the issue list](https://github.com/tiny-dnn/tiny-dnn/issues) to see if the problem has already been reported. 12 | - This can be skipped if the issue is trivial (fixing a typo, etc). 13 | 14 | ## Making Changes 15 | - Create a topic branch where you want to base your work. 16 | - This is usually the ```master``` branch. 17 | - Make commits. 18 | - Make sure you have added the necessary tests for your changes. 19 | - Submit a pull request. 20 | - Make sure all CI builds are passed. 21 | 22 | ## Coding guides 23 | - Keep header-only 24 | - Keep dependency-free 25 | - If your change requires 3rd party libraries, this should be __optional__ in tiny-dnn. 26 | Please guard your 3rd party dependent code by ```#ifdef - #endif``` block, and white CMakelist option to enable the block - 27 | but lesser these switches, the better. 28 | - Keep platform-independent 29 | - Use C++ standard library instead of Windows/POSIX dependent API 30 | - CPU/GPU optimized code should be extracted as a separated file, and should be guarded as preprocessor macro. 31 | 32 | ### Preferred coding style 33 | - Use ```snake_case``` for identifiers 34 | - Use ```SCREAMING_SNAKE_CASE_START_WITH_CNN``` for preprocessor macros. 35 | - Use 4-spaces instead of tabs. 36 | -------------------------------------------------------------------------------- /docs/developer_guides/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | Adding-a-new-layer 3 | How-to-contribute 4 | -------------------------------------------------------------------------------- /docs/device-abstraction-uml.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | class Session { 3 | -String name 4 | void schedule_session() 5 | void run_session() 6 | } 7 | 8 | abstract class Device { 9 | -int id 10 | } 11 | 12 | class Node { 13 | } 14 | 15 | class Edge { 16 | - shape3d shape 17 | } 18 | 19 | abstract class Layer { 20 | - String layer_type 21 | virtual void forward_propagation() 22 | virtual void backward_propagation() 23 | } 24 | 25 | class ConvolutionalLayer { 26 | } 27 | 28 | class MaxPoolingLayer { 29 | } 30 | 31 | abstract class Backend { 32 | virtual void matmul() 33 | virtual pool2d() 34 | virtual conv2d() 35 | virtual conv2d_back() 36 | } 37 | 38 | class TinyCNNBackend { 39 | } 40 | 41 | class NNPackBackend { 42 | } 43 | 44 | class LibDNNBackend { 45 | } 46 | 47 | Session *-- Device 48 | 49 | Device <|-- CPUDevice 50 | Device <|-- OCLDevice 51 | 52 | Node <|-- Layer 53 | Node *-- Edge : prev 54 | Node *-- Edge : next 55 | 56 | Edge --> Node : prev 57 | Edge *-- Node : next 58 | Edge *-- Data : data 59 | Edge *-- Data : grad 60 | 61 | Layer <|-- ConvolutionalLayer 62 | Layer <|-- MaxPoolingLayer 63 | 64 | Device *-- Backend : own_list 65 | ConvolutionalLayer *-- Backend : backend 66 | MaxPoolingLayer *-- Backend : backend 67 | 68 | Backend <|-- TinyCNNBackend 69 | Backend <|-- NNPackBackend 70 | Backend <|-- LibDNNBackend 71 | 72 | @enduml 73 | -------------------------------------------------------------------------------- /docs/getting_started/Getting-started.md: -------------------------------------------------------------------------------- 1 | # A quick introduction to tiny-dnn 2 | Include tiny_dnn.h: 3 | 4 | ```cpp 5 | #include "tiny_dnn/tiny_dnn.h" 6 | using namespace tiny_dnn; 7 | using namespace tiny_dnn::layers; 8 | using namespace tiny_dnn::activation; 9 | ``` 10 | 11 | Declare the model as ```network```. There are 2 types of network: ```network``` and ```network```. The sequential model is easier to construct. 12 | 13 | ```cpp 14 | network net; 15 | ``` 16 | 17 | Stack layers: 18 | 19 | ```cpp 20 | net << conv(32, 32, 5, 1, 6, padding::same) // in:32x32x1, 5x5conv, 6fmaps 21 | << max_pool(32, 32, 6, 2) // in:32x32x6, 2x2pooling 22 | << conv(16, 16, 5, 6, 16, padding::same) // in:16x16x6, 5x5conv, 16fmaps 23 | << max_pool(16, 16, 16, 2) // in:16x16x16, 2x2pooling 24 | << fc(8*8*16, 100) // in:8x8x16, out:100 25 | << fc(100, 10); // in:100 out:10 26 | ``` 27 | 28 | Some layer takes an activation as a template parameter : ```max_pool``` means "apply a relu activation after the pooling". if the layer has no successive activation, use ```max_pool``` instead. 29 | 30 | Declare the optimizer: 31 | 32 | ```cpp 33 | adagrad opt; 34 | ``` 35 | 36 | In addition to gradient descent, you can use modern optimizers such as adagrad, adadelta, adam. 37 | 38 | Now you can start the training: 39 | 40 | ```cpp 41 | int epochs = 50; 42 | int batch = 20; 43 | net.fit(opt, x_data, y_data, batch, epochs); 44 | ``` 45 | 46 | If you don't have the target vector but have the class-id, you can alternatively use ```train```. 47 | 48 | ```cpp 49 | net.train(opt, x_data, y_label, batch, epochs); 50 | ``` 51 | 52 | Validate the training result: 53 | 54 | ```cpp 55 | auto test_result = net.test(x_data, y_label); 56 | auto loss = net.get_loss(x_data, y_data); 57 | ``` 58 | 59 | Generate prediction on the new data: 60 | 61 | ```cpp 62 | auto y_vector = net.predict(x_data); 63 | auto y_label = net.predict_max_label(x_data); 64 | ``` 65 | 66 | Save the trained parameter: 67 | 68 | ```cpp 69 | ofstream ofs("data", std::ios::binary); 70 | ofs << net; 71 | ``` 72 | 73 | For a more in-depth about tiny-dnn, check out [MNIST classification](https://github.com/tiny-dnn/tiny-dnn/tree/master/examples/mnist) where you can see the end-to-end example. 74 | You will find tiny-dnn's API in [How-to](../how_tos/How-Tos.md). 75 | -------------------------------------------------------------------------------- /docs/getting_started/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | Getting-started 3 | -------------------------------------------------------------------------------- /docs/how_tos/Integrate-with-your-application.md: -------------------------------------------------------------------------------- 1 | # Integrate with your application 2 | Because tiny-dnn is header-only, integrating it with your application is extremely easy. We explain how to do it step-by-step. 3 | 4 | ## Step1/3: Include tiny_dnn.h in your application 5 | Just add the following line: 6 | ```cpp 7 | #include "tiny_dnn/tiny_dnn.h" 8 | ``` 9 | 10 | ## Step2/3: Enable C++11 options 11 | tiny-dnn uses C++11's core features and libraries. You must use the c++11 compliant compiler and compile with c++11-mode. 12 | 13 | ### Visual Studio(2013-) 14 | C++11 features are enabled by default, you have nothing to do about it. 15 | 16 | ### gcc(4.8-)/clang(3.3-) 17 | Use ```-std=c++11``` option to enable c++11-mode. 18 | 19 | > From gcc 6.0, the default compile mode for c++ is -std=gnu++14, so you don't need to add this option. 20 | 21 | 22 | ## Step3/3: Add include path of tiny-dnn to your build system 23 | Tell your build system where tiny-dnn exists. In gcc: 24 | 25 | ``` 26 | g++ -std=c++11 -Iyour-downloaded-path -O3 your-app.cpp -o your-app 27 | ``` 28 | 29 | > Another solution: place tiny-dnn's header files under your project root 30 | -------------------------------------------------------------------------------- /docs/how_tos/Train-network-with-your-dataset.md: -------------------------------------------------------------------------------- 1 | # Train network with your original dataset 2 | Here are some examples. 3 | 4 | ### 1. using opencv (image file => vec_t) 5 | 6 | ```cpp 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace boost::filesystem; 12 | 13 | // convert image to vec_t 14 | void convert_image(const std::string& imagefilename, 15 | double scale, 16 | int w, 17 | int h, 18 | std::vector& data) 19 | { 20 | auto img = cv::imread(imagefilename, cv::IMREAD_GRAYSCALE); 21 | if (img.data == nullptr) return; // cannot open, or it's not an image 22 | 23 | cv::Mat_ resized; 24 | cv::resize(img, resized, cv::Size(w, h)); 25 | vec_t d; 26 | 27 | std::transform(resized.begin(), resized.end(), std::back_inserter(d), 28 | [=](uint8_t c) { return c * scale; }); 29 | data.push_back(d); 30 | } 31 | 32 | // convert all images found in directory to vec_t 33 | void convert_images(const std::string& directory, 34 | double scale, 35 | int w, 36 | int h, 37 | std::vector& data) 38 | { 39 | path dpath(directory); 40 | 41 | BOOST_FOREACH(const path& p, 42 | std::make_pair(directory_iterator(dpath), directory_iterator())) { 43 | if (is_directory(p)) continue; 44 | convert_image(p.string(), scale, w, h, data); 45 | } 46 | } 47 | ``` 48 | 49 | Another example can be found in [issue#16](https://github.com/tiny-dnn/tiny-dnn/issues/16), which can treat color channels. 50 | 51 | ### 2. using [mnisten](https://github.com/nyanp/mnisten) (image file => idx format) 52 | mnisten is a library to convert image files to idx format. 53 | ``` 54 | mnisten -d my_image_files_directory_name -o my_prefix -s 32x32 55 | ``` 56 | After generating idx files, you can use parse_mnist_images / parse_mnist_labels utilities in mnist_parser.h 57 | 58 | ### 3. from levelDB (caffe style => [vec_t, label_t]) 59 | [Caffe](https://github.com/BVLC/caffe/) supports levelDB data format. Following code can convert levelDB created by Caffe into data/label arrays. 60 | 61 | ```cpp 62 | #include "leveldb/db.h" 63 | 64 | void convert_leveldb(const std::string& dbname, 65 | double scale, 66 | std::vector& data, 67 | std::vector& label) 68 | { 69 | leveldb::DB *db; 70 | leveldb::Options options; 71 | options.create_if_missing = false; 72 | auto status = leveldb::DB::Open(options, dbname, &db); 73 | 74 | leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions()); 75 | for (it->SeekToFirst(); it->Valid(); it->Next()) { 76 | const char* src = it->value().data(); 77 | size_t sz = it->value().size(); 78 | vec_t d; 79 | std::transform(src, src + sz - 1, std::back_inserter(d), 80 | [=](char c){ return c * scale; }); 81 | data.push_back(d); 82 | label.push_back(src[sz - 1]); 83 | } 84 | delete it; 85 | delete db; 86 | } 87 | ``` -------------------------------------------------------------------------------- /docs/how_tos/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | How-Tos 3 | Integrate-with-your-application 4 | Train-network-with-your-dataset 5 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | tiny-dnn documentations 2 | ######################## 3 | 4 | `tiny-dnn `_ is a header only, 5 | dependency free deep learning library written in C++. 6 | It is designed to be used in the real applications, 7 | including IoT devices and embedded systems. 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | 12 | getting_started/index 13 | 14 | 15 | .. toctree:: 16 | :maxdepth: 2 17 | 18 | how_tos/index 19 | 20 | 21 | .. toctree:: 22 | :maxdepth: 2 23 | 24 | update_log/index 25 | 26 | 27 | .. toctree:: 28 | :maxdepth: 2 29 | 30 | developer_guides/index 31 | 32 | External Links 33 | ******************** 34 | I'm willing to update this list if your software use tiny-dnn. Please contact me at Email(see my github profile). 35 | 36 | Official Examples 37 | =================== 38 | 39 | * `MNIST image classification `_ 40 | * `Cifar-10 image classification `_ 41 | * `Deconvolutional Auto-encoder `_ 42 | * `Importing Caffe's model into tiny-dnn `_ 43 | 44 | Applications 45 | =================== 46 | 47 | * `zhangqianhui/CnnForAndroid `_ - A Vehicle Recognition Project using Convolutional Neural Network(CNN) in Android platform 48 | * `edgarriba/opencv_contrib `_ (in progress) - A new opencv's dnn module which use tiny-dnn as its backend 49 | -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # tiny-dnn documentations 2 | 3 | A built version of document is available at [http://tiny-dnn.readthedocs.io/en/latest/index.html](here). 4 | 5 | ## Local build 6 | 7 | You can build html documents in your local machine if you prefer. 8 | Assuming you have python already, install Sphinx and recommonmark at first: 9 | 10 | ```bash 11 | $ pip install sphinx sphinx-autobuild 12 | $ pip install recommonmark 13 | ``` 14 | 15 | #### build on Windows 16 | ```bach 17 | cd docs 18 | make.bat 19 | ``` 20 | 21 | #### build on Linux 22 | ```bash 23 | cd docs 24 | make 25 | ``` -------------------------------------------------------------------------------- /docs/resource/graph.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiny-dnn/dnn-serialize/fbb002e06e829c9e0562c04f1f2af9261dce0fe1/docs/resource/graph.gif -------------------------------------------------------------------------------- /docs/update_log/index.rst: -------------------------------------------------------------------------------- 1 | .. toctree:: 2 | v0_0_1-to-v0_1_0 3 | -------------------------------------------------------------------------------- /docs/update_log/v0_0_1-to-v0_1_0.md: -------------------------------------------------------------------------------- 1 | # Changing from v0.0.1 2 | This section explains the API changes from v0.0.1. 3 | 4 | ## How to specify the loss and the optimizer 5 | In v0.0.1, the loss function and the optimization algorithm are treated as template parameter of ```network```. 6 | 7 | ```cpp 8 | //v0.0.1 9 | network net; 10 | net.train(x_data, y_label, n_batch, n_epoch); 11 | ``` 12 | 13 | From v0.1.0, these are treated as parameters of train/fit functions. 14 | 15 | ```cpp 16 | //v0.1.0 17 | network net; 18 | adagrad opt; 19 | net.fit(opt, x_data, y_label, n_batch, n_epoch); 20 | ``` 21 | 22 | ## Training API for regression 23 | In v0.0.1, the regression and the classification have the same API: 24 | 25 | ```cpp 26 | //v0.0.1 27 | net.train(x_data, y_data, n_batch, n_epoch); // regression 28 | net.train(x_data, y_label, n_batch, n_epoch); // classification 29 | ``` 30 | 31 | From v0.1.0, these are separated into ```fit``` and ```train```. 32 | 33 | ```cpp 34 | //v0.1.0 35 | net.fit(opt, x_data, y_data, n_batch, n_epoch); // regression 36 | net.train(opt, x_data, y_label, n_batch, n_epoch); // classification 37 | ``` 38 | 39 | ## The default mode of re-init weights 40 | In v0.0.1, the default mode of weight-initialization in ```trian``` function is ```reset_weights=true```. 41 | 42 | ```cpp 43 | //v0.0.1 44 | std::ifstream is("model"); 45 | is >> net; 46 | net.train(x_data, y_data, n_batch, n_epoch); // reset loaded weights automatically 47 | net.train(x_data, y_data, n_bacth, n_epoch); // again we lost trained parameter we got the last training 48 | ``` 49 | 50 | ```cpp 51 | //v0.1.0 52 | std::ifstream is("model"); 53 | is >> net; 54 | net.trian(opt, x_data, y_data, n_batch, n_epoch); // hold loaded weights 55 | net.train(opt, x_data, y_data, n_bacth, n_epoch); // continue training from the last training 56 | 57 | // weights are automatically initialized if we don't load models and train yet 58 | net2.train(opt, x_data, y_data, n_batch, n_epoch); 59 | ``` 60 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | dnn serialization concept using [cereal](https://github.com/USCiLab/cereal) 2 | -------------------------------------------------------------------------------- /test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | class layer { 14 | public: 15 | virtual std::string name() const = 0; 16 | virtual std::shared_ptr clone() const = 0; 17 | }; 18 | 19 | #define IMPLEMENT_CLONE_AND_SERIALIZATION(type, layer_name) \ 20 | virtual std::string name() const { \ 21 | return layer_name; \ 22 | } \ 23 | virtual std::shared_ptr clone() const { \ 24 | return std::make_shared(p); \ 25 | } \ 26 | template \ 27 | void serialize(Archive & archive) { \ 28 | p.serialize(archive); \ 29 | } 30 | 31 | 32 | 33 | ////////////////////////// 34 | // conv-layer 35 | 36 | struct conv_param { 37 | size_t window_w; 38 | size_t window_h; 39 | size_t out_channels; 40 | 41 | template 42 | void serialize(Archive & archive) 43 | { 44 | archive(CEREAL_NVP(window_w), CEREAL_NVP(window_h), CEREAL_NVP(out_channels)); 45 | } 46 | }; 47 | 48 | 49 | class conv_layer : public layer { 50 | public: 51 | conv_layer() {} 52 | explicit conv_layer(const conv_param& p) : p(p) {} 53 | conv_layer(size_t window_size, size_t out_channels) : p({ window_size, window_size, out_channels }) {} 54 | 55 | IMPLEMENT_CLONE_AND_SERIALIZATION(conv_layer, "conv") 56 | 57 | private: 58 | conv_param p; 59 | }; 60 | 61 | ////////////////////////// 62 | // fc-layer 63 | 64 | struct fc_param { 65 | size_t out_size; 66 | bool has_bias; 67 | 68 | template 69 | void serialize(Archive & archive) 70 | { 71 | archive(CEREAL_NVP(out_size), CEREAL_NVP(has_bias)); 72 | } 73 | }; 74 | 75 | class fc_layer : public layer { 76 | public: 77 | fc_layer() {} 78 | explicit fc_layer(const fc_param& p) : p(p) {} 79 | explicit fc_layer(size_t out_size) : p({out_size, true}) {} 80 | 81 | IMPLEMENT_CLONE_AND_SERIALIZATION(fc_layer, "fc") 82 | 83 | private: 84 | fc_param p; 85 | }; 86 | 87 | ///////////////////////////// 88 | // nodes(graph) 89 | 90 | typedef layer* layerptr_t; 91 | 92 | class nodes { 93 | public: 94 | 95 | void add(std::shared_ptr layer) { 96 | own_nodes_.push_back(layer); 97 | nodes_.push_back(&*layer); 98 | } 99 | 100 | void add(layerptr_t layer) { 101 | nodes_.push_back(layer); 102 | } 103 | 104 | 105 | void save(std::ostream& os) const { 106 | std::vector> tmp(own_nodes_); 107 | // clone all layers which nodes don't have its ownership 108 | for (auto n : nodes_) { 109 | if (!own(n)) { 110 | tmp.push_back(n->clone()); 111 | } 112 | } 113 | cereal::JSONOutputArchive o_archive(os); 114 | o_archive(tmp); 115 | 116 | // TODO: save graph-connection structure 117 | } 118 | 119 | void load(std::istream& is) { 120 | cereal::JSONInputArchive i_archive(is); 121 | i_archive(own_nodes_); 122 | 123 | for (auto& n : own_nodes_) { 124 | nodes_.push_back(&*n); 125 | } 126 | } 127 | private: 128 | bool own(layerptr_t l) const { 129 | for (auto& n : own_nodes_) { 130 | if (&*n == l) return true; 131 | } 132 | return false; 133 | } 134 | std::vector > own_nodes_; 135 | std::vector nodes_; 136 | }; 137 | 138 | // Register DerivedClassOne 139 | CEREAL_REGISTER_TYPE(conv_layer); 140 | 141 | // Register EmbarassingDerivedClass with a less embarrasing name 142 | CEREAL_REGISTER_TYPE(fc_layer); 143 | 144 | // Note that there is no need to register the base class, only derived classes 145 | // However, since we did not use cereal::base_class, we need to clarify 146 | // the relationship (more on this later) 147 | CEREAL_REGISTER_POLYMORPHIC_RELATION(layer, conv_layer); 148 | CEREAL_REGISTER_POLYMORPHIC_RELATION(layer, fc_layer); 149 | 150 | int main(void) { 151 | fc_layer l1(3); 152 | conv_layer l2(5, 2); 153 | 154 | nodes n; 155 | n.add(std::make_shared(l1)); 156 | n.add(&l2); 157 | 158 | std::stringstream ss; 159 | n.save(ss); 160 | 161 | std::cout << ss.str(); 162 | 163 | nodes n2; 164 | n2.load(ss); 165 | 166 | /*{ 167 | cereal::JSONOutputArchive oarchive(std::cout); 168 | 169 | // Create instances of the derived classes, but only keep base class pointers 170 | std::shared_ptr ptr1 = std::make_shared(cv); 171 | std::shared_ptr ptr2 = std::make_shared(fc); 172 | oarchive(ptr1, ptr2); 173 | }*/ 174 | } -------------------------------------------------------------------------------- /third_party/cereal/archives/adapters.hpp: -------------------------------------------------------------------------------- 1 | /*! \file adapters.hpp 2 | \brief Archive adapters that provide additional functionality 3 | on top of an existing archive */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_ARCHIVES_ADAPTERS_HPP_ 31 | #define CEREAL_ARCHIVES_ADAPTERS_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | #ifdef CEREAL_FUTURE_EXPERIMENTAL 39 | 40 | // Forward declaration for friend access 41 | template U & get_user_data( A & ); 42 | 43 | //! Wraps an archive and gives access to user data 44 | /*! This adapter is useful if you require access to 45 | either raw pointers or references within your 46 | serialization functions. 47 | 48 | While cereal does not directly support serialization 49 | raw pointers or references, it is sometimes the case 50 | that you may want to supply something such as a raw 51 | pointer or global reference to some constructor. 52 | In this situation this adapter would likely be used 53 | with the construct class to allow for non-default 54 | constructors. 55 | 56 | @note This feature is experimental and may be altered or removed in a future release. See issue #46. 57 | 58 | @code{.cpp} 59 | struct MyUserData 60 | { 61 | int * myRawPointer; 62 | std::reference_wrapper myReference; 63 | }; 64 | 65 | struct MyClass 66 | { 67 | // Note the raw pointer parameter 68 | MyClass( int xx, int * rawP ); 69 | 70 | int x; 71 | 72 | template 73 | void serialize( Archive & ar ) 74 | { ar( x ); } 75 | 76 | template 77 | static void load_and_construct( Archive & ar, cereal::construct & construct ) 78 | { 79 | int xx; 80 | ar( xx ); 81 | // note the need to use get_user_data to retrieve user data from the archive 82 | construct( xx, cereal::get_user_data( ar ).myRawPointer ); 83 | } 84 | }; 85 | 86 | int main() 87 | { 88 | { 89 | MyUserData md; 90 | md.myRawPointer = &something; 91 | md.myReference = someInstanceOfType; 92 | 93 | std::ifstream is( "data.xml" ); 94 | cereal::UserDataAdapter ar( md, is ); 95 | 96 | std::unique_ptr sc; 97 | ar( sc ); // use as normal 98 | } 99 | 100 | return 0; 101 | } 102 | @endcode 103 | 104 | @relates get_user_data 105 | 106 | @tparam UserData The type to give the archive access to 107 | @tparam Archive The archive to wrap */ 108 | template 109 | class UserDataAdapter : public Archive 110 | { 111 | public: 112 | //! Construct the archive with some user data struct 113 | /*! This will forward all arguments (other than the user 114 | data) to the wrapped archive type. The UserDataAdapter 115 | can then be used identically to the wrapped archive type 116 | 117 | @tparam Args The arguments to pass to the constructor of 118 | the archive. */ 119 | template 120 | UserDataAdapter( UserData & ud, Args && ... args ) : 121 | Archive( std::forward( args )... ), 122 | userdata( ud ) 123 | { } 124 | 125 | private: 126 | //! Overload the rtti function to enable dynamic_cast 127 | void rtti() {} 128 | friend UserData & get_user_data( Archive & ar ); 129 | UserData & userdata; //!< The actual user data 130 | }; 131 | 132 | //! Retrieves user data from an archive wrapped by UserDataAdapter 133 | /*! This will attempt to retrieve the user data associated with 134 | some archive wrapped by UserDataAdapter. If this is used on 135 | an archive that is not wrapped, a run-time exception will occur. 136 | 137 | @note This feature is experimental and may be altered or removed in a future release. See issue #46. 138 | 139 | @note The correct use of this function cannot be enforced at compile 140 | time. 141 | 142 | @relates UserDataAdapter 143 | @tparam UserData The data struct contained in the archive 144 | @tparam Archive The archive, which should be wrapped by UserDataAdapter 145 | @param ar The archive 146 | @throws Exception if the archive this is used upon is not wrapped with 147 | UserDataAdapter. */ 148 | template 149 | UserData & get_user_data( Archive & ar ) 150 | { 151 | try 152 | { 153 | return dynamic_cast &>( ar ).userdata; 154 | } 155 | catch( std::bad_cast const & ) 156 | { 157 | throw ::cereal::Exception("Attempting to get user data from archive not wrapped in UserDataAdapter"); 158 | } 159 | } 160 | #endif // CEREAL_FUTURE_EXPERIMENTAL 161 | } // namespace cereal 162 | 163 | #endif // CEREAL_ARCHIVES_ADAPTERS_HPP_ 164 | -------------------------------------------------------------------------------- /third_party/cereal/archives/binary.hpp: -------------------------------------------------------------------------------- 1 | /*! \file binary.hpp 2 | \brief Binary input and output archives */ 3 | /* 4 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of cereal nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef CEREAL_ARCHIVES_BINARY_HPP_ 30 | #define CEREAL_ARCHIVES_BINARY_HPP_ 31 | 32 | #include 33 | #include 34 | 35 | namespace cereal 36 | { 37 | // ###################################################################### 38 | //! An output archive designed to save data in a compact binary representation 39 | /*! This archive outputs data to a stream in an extremely compact binary 40 | representation with as little extra metadata as possible. 41 | 42 | This archive does nothing to ensure that the endianness of the saved 43 | and loaded data is the same. If you need to have portability over 44 | architectures with different endianness, use PortableBinaryOutputArchive. 45 | 46 | When using a binary archive and a file stream, you must use the 47 | std::ios::binary format flag to avoid having your data altered 48 | inadvertently. 49 | 50 | \ingroup Archives */ 51 | class BinaryOutputArchive : public OutputArchive 52 | { 53 | public: 54 | //! Construct, outputting to the provided stream 55 | /*! @param stream The stream to output to. Can be a stringstream, a file stream, or 56 | even cout! */ 57 | BinaryOutputArchive(std::ostream & stream) : 58 | OutputArchive(this), 59 | itsStream(stream) 60 | { } 61 | 62 | ~BinaryOutputArchive() CEREAL_NOEXCEPT = default; 63 | 64 | //! Writes size bytes of data to the output stream 65 | void saveBinary( const void * data, std::size_t size ) 66 | { 67 | auto const writtenSize = static_cast( itsStream.rdbuf()->sputn( reinterpret_cast( data ), size ) ); 68 | 69 | if(writtenSize != size) 70 | throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + std::to_string(writtenSize)); 71 | } 72 | 73 | private: 74 | std::ostream & itsStream; 75 | }; 76 | 77 | // ###################################################################### 78 | //! An input archive designed to load data saved using BinaryOutputArchive 79 | /* This archive does nothing to ensure that the endianness of the saved 80 | and loaded data is the same. If you need to have portability over 81 | architectures with different endianness, use PortableBinaryOutputArchive. 82 | 83 | When using a binary archive and a file stream, you must use the 84 | std::ios::binary format flag to avoid having your data altered 85 | inadvertently. 86 | 87 | \ingroup Archives */ 88 | class BinaryInputArchive : public InputArchive 89 | { 90 | public: 91 | //! Construct, loading from the provided stream 92 | BinaryInputArchive(std::istream & stream) : 93 | InputArchive(this), 94 | itsStream(stream) 95 | { } 96 | 97 | ~BinaryInputArchive() CEREAL_NOEXCEPT = default; 98 | 99 | //! Reads size bytes of data from the input stream 100 | void loadBinary( void * const data, std::size_t size ) 101 | { 102 | auto const readSize = static_cast( itsStream.rdbuf()->sgetn( reinterpret_cast( data ), size ) ); 103 | 104 | if(readSize != size) 105 | throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + std::to_string(readSize)); 106 | } 107 | 108 | private: 109 | std::istream & itsStream; 110 | }; 111 | 112 | // ###################################################################### 113 | // Common BinaryArchive serialization functions 114 | 115 | //! Saving for POD types to binary 116 | template inline 117 | typename std::enable_if::value, void>::type 118 | CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, T const & t) 119 | { 120 | ar.saveBinary(std::addressof(t), sizeof(t)); 121 | } 122 | 123 | //! Loading for POD types from binary 124 | template inline 125 | typename std::enable_if::value, void>::type 126 | CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, T & t) 127 | { 128 | ar.loadBinary(std::addressof(t), sizeof(t)); 129 | } 130 | 131 | //! Serializing NVP types to binary 132 | template inline 133 | CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) 134 | CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, NameValuePair & t ) 135 | { 136 | ar( t.value ); 137 | } 138 | 139 | //! Serializing SizeTags to binary 140 | template inline 141 | CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) 142 | CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, SizeTag & t ) 143 | { 144 | ar( t.size ); 145 | } 146 | 147 | //! Saving binary data 148 | template inline 149 | void CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, BinaryData const & bd) 150 | { 151 | ar.saveBinary( bd.data, static_cast( bd.size ) ); 152 | } 153 | 154 | //! Loading binary data 155 | template inline 156 | void CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, BinaryData & bd) 157 | { 158 | ar.loadBinary(bd.data, static_cast(bd.size)); 159 | } 160 | } // namespace cereal 161 | 162 | // register archives for polymorphic support 163 | CEREAL_REGISTER_ARCHIVE(cereal::BinaryOutputArchive) 164 | CEREAL_REGISTER_ARCHIVE(cereal::BinaryInputArchive) 165 | 166 | // tie input and output archives together 167 | CEREAL_SETUP_ARCHIVE_TRAITS(cereal::BinaryInputArchive, cereal::BinaryOutputArchive) 168 | 169 | #endif // CEREAL_ARCHIVES_BINARY_HPP_ 170 | -------------------------------------------------------------------------------- /third_party/cereal/details/polymorphic_impl_fwd.hpp: -------------------------------------------------------------------------------- 1 | /*! \file polymorphic_impl_fwd.hpp 2 | \brief Internal polymorphism support forward declarations 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* This code is heavily inspired by the boost serialization implementation by the following authors 32 | 33 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 34 | Use, modification and distribution is subject to the Boost Software 35 | License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) 36 | 37 | See http://www.boost.org for updates, documentation, and revision history. 38 | 39 | (C) Copyright 2006 David Abrahams - http://www.boost.org. 40 | 41 | See /boost/serialization/export.hpp and /boost/archive/detail/register_archive.hpp for their 42 | implementation. 43 | */ 44 | 45 | #ifndef CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 46 | #define CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 47 | 48 | namespace cereal 49 | { 50 | namespace detail 51 | { 52 | //! Forward declaration, see polymorphic_impl.hpp for more information 53 | template 54 | struct RegisterPolymorphicCaster; 55 | 56 | //! Forward declaration, see polymorphic_impl.hpp for more information 57 | struct PolymorphicCasters; 58 | 59 | //! Forward declaration, see polymorphic_impl.hpp for more information 60 | template 61 | struct PolymorphicRelation; 62 | } // namespace detail 63 | } // namespace cereal 64 | 65 | #endif // CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 66 | -------------------------------------------------------------------------------- /third_party/cereal/details/static_object.hpp: -------------------------------------------------------------------------------- 1 | /*! \file static_object.hpp 2 | \brief Internal polymorphism static object support 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of cereal nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | #ifndef CEREAL_DETAILS_STATIC_OBJECT_HPP_ 29 | #define CEREAL_DETAILS_STATIC_OBJECT_HPP_ 30 | 31 | #include 32 | 33 | #if CEREAL_THREAD_SAFE 34 | #include 35 | #endif 36 | 37 | //! Prevent link optimization from removing non-referenced static objects 38 | /*! Especially for polymorphic support, we create static objects which 39 | may not ever be explicitly referenced. Most linkers will detect this 40 | and remove the code causing various unpleasant runtime errors. These 41 | macros, adopted from Boost (see force_include.hpp) prevent this 42 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 43 | Use, modification and distribution is subject to the Boost Software 44 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 45 | http://www.boost.org/LICENSE_1_0.txt) */ 46 | 47 | #ifdef _MSC_VER 48 | # define CEREAL_DLL_EXPORT __declspec(dllexport) 49 | # define CEREAL_USED 50 | #else // clang or gcc 51 | # define CEREAL_DLL_EXPORT 52 | # define CEREAL_USED __attribute__ ((__used__)) 53 | #endif 54 | 55 | namespace cereal 56 | { 57 | namespace detail 58 | { 59 | //! A static, pre-execution object 60 | /*! This class will create a single copy (singleton) of some 61 | type and ensures that merely referencing this type will 62 | cause it to be instantiated and initialized pre-execution. 63 | For example, this is used heavily in the polymorphic pointer 64 | serialization mechanisms to bind various archive types with 65 | different polymorphic classes */ 66 | template 67 | class CEREAL_DLL_EXPORT StaticObject 68 | { 69 | private: 70 | //! Forces instantiation at pre-execution time 71 | static void instantiate( T const & ) {} 72 | 73 | static T & create() 74 | { 75 | static T t; 76 | instantiate(instance); 77 | return t; 78 | } 79 | 80 | StaticObject( StaticObject const & /*other*/ ) {} 81 | 82 | public: 83 | static T & getInstance() 84 | { 85 | return create(); 86 | } 87 | 88 | //! A class that acts like std::lock_guard 89 | class LockGuard 90 | { 91 | #if CEREAL_THREAD_SAFE 92 | public: 93 | LockGuard(std::mutex & m) : lock(m) {} 94 | private: 95 | std::unique_lock lock; 96 | #else 97 | public: 98 | ~LockGuard() CEREAL_NOEXCEPT {} // prevents variable not used 99 | #endif 100 | }; 101 | 102 | //! Attempts to lock this static object for the current scope 103 | /*! @note This function is a no-op if cereal is not compiled with 104 | thread safety enabled (CEREAL_THREAD_SAFE = 1). 105 | 106 | This function returns an object that holds a lock for 107 | this StaticObject that will release its lock upon destruction. This 108 | call will block until the lock is available. */ 109 | static LockGuard lock() 110 | { 111 | #if CEREAL_THREAD_SAFE 112 | return LockGuard{instanceMutex}; 113 | #else 114 | return LockGuard{}; 115 | #endif 116 | } 117 | 118 | private: 119 | static T & instance; 120 | #if CEREAL_THREAD_SAFE 121 | static std::mutex instanceMutex; 122 | #endif 123 | }; 124 | 125 | template T & StaticObject::instance = StaticObject::create(); 126 | #if CEREAL_THREAD_SAFE 127 | template std::mutex StaticObject::instanceMutex; 128 | #endif 129 | } // namespace detail 130 | } // namespace cereal 131 | 132 | #endif // CEREAL_DETAILS_STATIC_OBJECT_HPP_ 133 | -------------------------------------------------------------------------------- /third_party/cereal/details/util.hpp: -------------------------------------------------------------------------------- 1 | /*! \file util.hpp 2 | \brief Internal misc utilities 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_DETAILS_UTIL_HPP_ 31 | #define CEREAL_DETAILS_UTIL_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | namespace cereal 38 | { 39 | namespace util 40 | { 41 | //! Demangles the type encoded in a string 42 | /*! @internal */ 43 | inline std::string demangle( std::string const & name ) 44 | { return name; } 45 | 46 | //! Gets the demangled name of a type 47 | /*! @internal */ 48 | template inline 49 | std::string demangledName() 50 | { return typeid( T ).name(); } 51 | } // namespace util 52 | } // namespace cereal 53 | #else // clang or gcc 54 | #include 55 | #include 56 | namespace cereal 57 | { 58 | namespace util 59 | { 60 | //! Demangles the type encoded in a string 61 | /*! @internal */ 62 | inline std::string demangle(std::string mangledName) 63 | { 64 | int status = 0; 65 | char *demangledName = nullptr; 66 | std::size_t len; 67 | 68 | demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status); 69 | 70 | std::string retName(demangledName); 71 | free(demangledName); 72 | 73 | return retName; 74 | } 75 | 76 | //! Gets the demangled name of a type 77 | /*! @internal */ 78 | template inline 79 | std::string demangledName() 80 | { return demangle(typeid(T).name()); } 81 | } 82 | } // namespace cereal 83 | #endif // clang or gcc branch of _MSC_VER 84 | #endif // CEREAL_DETAILS_UTIL_HPP_ 85 | -------------------------------------------------------------------------------- /third_party/cereal/external/base64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2004-2008 René Nyffenegger 3 | 4 | This source code is provided 'as-is', without any express or implied 5 | warranty. In no event will the author be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this source code must not be misrepresented; you must not 13 | claim that you wrote the original source code. If you use this source code 14 | in a product, an acknowledgment in the product documentation would be 15 | appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original source code. 19 | 20 | 3. This notice may not be removed or altered from any source distribution. 21 | 22 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 23 | */ 24 | 25 | #ifndef CEREAL_EXTERNAL_BASE64_HPP_ 26 | #define CEREAL_EXTERNAL_BASE64_HPP_ 27 | 28 | #include 29 | 30 | namespace cereal 31 | { 32 | namespace base64 33 | { 34 | static const std::string chars = 35 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 36 | "abcdefghijklmnopqrstuvwxyz" 37 | "0123456789+/"; 38 | 39 | static inline bool is_base64(unsigned char c) { 40 | return (isalnum(c) || (c == '+') || (c == '/')); 41 | } 42 | 43 | inline std::string encode(unsigned char const* bytes_to_encode, size_t in_len) { 44 | std::string ret; 45 | int i = 0; 46 | int j = 0; 47 | unsigned char char_array_3[3]; 48 | unsigned char char_array_4[4]; 49 | 50 | while (in_len--) { 51 | char_array_3[i++] = *(bytes_to_encode++); 52 | if (i == 3) { 53 | char_array_4[0] = (unsigned char) ((char_array_3[0] & 0xfc) >> 2); 54 | char_array_4[1] = (unsigned char) ( ( ( char_array_3[0] & 0x03 ) << 4 ) + ( ( char_array_3[1] & 0xf0 ) >> 4 ) ); 55 | char_array_4[2] = (unsigned char) ( ( ( char_array_3[1] & 0x0f ) << 2 ) + ( ( char_array_3[2] & 0xc0 ) >> 6 ) ); 56 | char_array_4[3] = (unsigned char) ( char_array_3[2] & 0x3f ); 57 | 58 | for(i = 0; (i <4) ; i++) 59 | ret += chars[char_array_4[i]]; 60 | i = 0; 61 | } 62 | } 63 | 64 | if (i) 65 | { 66 | for(j = i; j < 3; j++) 67 | char_array_3[j] = '\0'; 68 | 69 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 70 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 71 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 72 | char_array_4[3] = char_array_3[2] & 0x3f; 73 | 74 | for (j = 0; (j < i + 1); j++) 75 | ret += chars[char_array_4[j]]; 76 | 77 | while((i++ < 3)) 78 | ret += '='; 79 | 80 | } 81 | 82 | return ret; 83 | 84 | } 85 | 86 | inline std::string decode(std::string const& encoded_string) { 87 | size_t in_len = encoded_string.size(); 88 | size_t i = 0; 89 | size_t j = 0; 90 | int in_ = 0; 91 | unsigned char char_array_4[4], char_array_3[3]; 92 | std::string ret; 93 | 94 | while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { 95 | char_array_4[i++] = encoded_string[in_]; in_++; 96 | if (i ==4) { 97 | for (i = 0; i <4; i++) 98 | char_array_4[i] = (unsigned char) chars.find( char_array_4[i] ); 99 | 100 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 101 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 102 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 103 | 104 | for (i = 0; (i < 3); i++) 105 | ret += char_array_3[i]; 106 | i = 0; 107 | } 108 | } 109 | 110 | if (i) { 111 | for (j = i; j <4; j++) 112 | char_array_4[j] = 0; 113 | 114 | for (j = 0; j <4; j++) 115 | char_array_4[j] = (unsigned char) chars.find( char_array_4[j] ); 116 | 117 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 118 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 119 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 120 | 121 | for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; 122 | } 123 | 124 | return ret; 125 | } 126 | } // namespace base64 127 | } // namespace cereal 128 | 129 | #endif // CEREAL_EXTERNAL_BASE64_HPP_ 130 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/error/en.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_ERROR_EN_H_ 16 | #define CEREAL_RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(switch-enum) 23 | CEREAL_RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup CEREAL_RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const CEREAL_RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return CEREAL_RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return CEREAL_RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return CEREAL_RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return CEREAL_RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return CEREAL_RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return CEREAL_RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return CEREAL_RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return CEREAL_RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return CEREAL_RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return CEREAL_RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return CEREAL_RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return CEREAL_RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | CEREAL_RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | CEREAL_RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // CEREAL_RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/error/error.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_ERROR_ERROR_H_ 16 | #define CEREAL_RAPIDJSON_ERROR_ERROR_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 23 | #endif 24 | 25 | /*! \file error.h */ 26 | 27 | /*! \defgroup CEREAL_RAPIDJSON_ERRORS RapidJSON error handling */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // CEREAL_RAPIDJSON_ERROR_CHARTYPE 31 | 32 | //! Character type of error messages. 33 | /*! \ingroup CEREAL_RAPIDJSON_ERRORS 34 | The default character type is \c char. 35 | On Windows, user can define this macro as \c TCHAR for supporting both 36 | unicode/non-unicode settings. 37 | */ 38 | #ifndef CEREAL_RAPIDJSON_ERROR_CHARTYPE 39 | #define CEREAL_RAPIDJSON_ERROR_CHARTYPE char 40 | #endif 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // CEREAL_RAPIDJSON_ERROR_STRING 44 | 45 | //! Macro for converting string literial to \ref CEREAL_RAPIDJSON_ERROR_CHARTYPE[]. 46 | /*! \ingroup CEREAL_RAPIDJSON_ERRORS 47 | By default this conversion macro does nothing. 48 | On Windows, user can define this macro as \c _T(x) for supporting both 49 | unicode/non-unicode settings. 50 | */ 51 | #ifndef CEREAL_RAPIDJSON_ERROR_STRING 52 | #define CEREAL_RAPIDJSON_ERROR_STRING(x) x 53 | #endif 54 | 55 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 56 | 57 | /////////////////////////////////////////////////////////////////////////////// 58 | // ParseErrorCode 59 | 60 | //! Error code of parsing. 61 | /*! \ingroup CEREAL_RAPIDJSON_ERRORS 62 | \see GenericReader::Parse, GenericReader::GetParseErrorCode 63 | */ 64 | enum ParseErrorCode { 65 | kParseErrorNone = 0, //!< No error. 66 | 67 | kParseErrorDocumentEmpty, //!< The document is empty. 68 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 69 | 70 | kParseErrorValueInvalid, //!< Invalid value. 71 | 72 | kParseErrorObjectMissName, //!< Missing a name for object member. 73 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 74 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 75 | 76 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 77 | 78 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 79 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 80 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 81 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 82 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 83 | 84 | kParseErrorNumberTooBig, //!< Number too big to be stored in double. 85 | kParseErrorNumberMissFraction, //!< Miss fraction part in number. 86 | kParseErrorNumberMissExponent, //!< Miss exponent in number. 87 | 88 | kParseErrorTermination, //!< Parsing was terminated. 89 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 90 | }; 91 | 92 | //! Result of parsing (wraps ParseErrorCode) 93 | /*! 94 | \ingroup CEREAL_RAPIDJSON_ERRORS 95 | \code 96 | Document doc; 97 | ParseResult ok = doc.Parse("[42]"); 98 | if (!ok) { 99 | fprintf(stderr, "JSON parse error: %s (%u)", 100 | GetParseError_En(ok.Code()), ok.Offset()); 101 | exit(EXIT_FAILURE); 102 | } 103 | \endcode 104 | \see GenericReader::Parse, GenericDocument::Parse 105 | */ 106 | struct ParseResult { 107 | public: 108 | //! Default constructor, no error. 109 | ParseResult() : code_(kParseErrorNone), offset_(0) {} 110 | //! Constructor to set an error. 111 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 112 | 113 | //! Get the error code. 114 | ParseErrorCode Code() const { return code_; } 115 | //! Get the error offset, if \ref IsError(), 0 otherwise. 116 | size_t Offset() const { return offset_; } 117 | 118 | //! Conversion to \c bool, returns \c true, iff !\ref IsError(). 119 | operator bool() const { return !IsError(); } 120 | //! Whether the result is an error. 121 | bool IsError() const { return code_ != kParseErrorNone; } 122 | 123 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } 124 | bool operator==(ParseErrorCode code) const { return code_ == code; } 125 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 126 | 127 | //! Reset error code. 128 | void Clear() { Set(kParseErrorNone); } 129 | //! Update error code and offset. 130 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 131 | 132 | private: 133 | ParseErrorCode code_; 134 | size_t offset_; 135 | }; 136 | 137 | //! Function pointer type of GetParseError(). 138 | /*! \ingroup CEREAL_RAPIDJSON_ERRORS 139 | 140 | This is the prototype for \c GetParseError_X(), where \c X is a locale. 141 | User can dynamically change locale in runtime, e.g.: 142 | \code 143 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 144 | const CEREAL_RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 145 | \endcode 146 | */ 147 | typedef const CEREAL_RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 148 | 149 | CEREAL_RAPIDJSON_NAMESPACE_END 150 | 151 | #ifdef __clang__ 152 | CEREAL_RAPIDJSON_DIAG_POP 153 | #endif 154 | 155 | #endif // CEREAL_RAPIDJSON_ERROR_ERROR_H_ 156 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 25 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 46 | CEREAL_RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 56 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | CEREAL_RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | CEREAL_RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for input using fread(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | CEREAL_RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | CEREAL_RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/fwd.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FWD_H_ 16 | #define CEREAL_RAPIDJSON_FWD_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | // encodings.h 23 | 24 | template struct UTF8; 25 | template struct UTF16; 26 | template struct UTF16BE; 27 | template struct UTF16LE; 28 | template struct UTF32; 29 | template struct UTF32BE; 30 | template struct UTF32LE; 31 | template struct ASCII; 32 | template struct AutoUTF; 33 | 34 | template 35 | struct Transcoder; 36 | 37 | // allocators.h 38 | 39 | class CrtAllocator; 40 | 41 | template 42 | class MemoryPoolAllocator; 43 | 44 | // stream.h 45 | 46 | template 47 | struct GenericStringStream; 48 | 49 | typedef GenericStringStream > StringStream; 50 | 51 | template 52 | struct GenericInsituStringStream; 53 | 54 | typedef GenericInsituStringStream > InsituStringStream; 55 | 56 | // stringbuffer.h 57 | 58 | template 59 | class GenericStringBuffer; 60 | 61 | typedef GenericStringBuffer, CrtAllocator> StringBuffer; 62 | 63 | // filereadstream.h 64 | 65 | class FileReadStream; 66 | 67 | // filewritestream.h 68 | 69 | class FileWriteStream; 70 | 71 | // memorybuffer.h 72 | 73 | template 74 | struct GenericMemoryBuffer; 75 | 76 | typedef GenericMemoryBuffer MemoryBuffer; 77 | 78 | // memorystream.h 79 | 80 | struct MemoryStream; 81 | 82 | // reader.h 83 | 84 | template 85 | struct BaseReaderHandler; 86 | 87 | template 88 | class GenericReader; 89 | 90 | typedef GenericReader, UTF8, CrtAllocator> Reader; 91 | 92 | // writer.h 93 | 94 | template 95 | class Writer; 96 | 97 | // prettywriter.h 98 | 99 | template 100 | class PrettyWriter; 101 | 102 | // document.h 103 | 104 | template 105 | struct GenericMember; 106 | 107 | template 108 | class GenericMemberIterator; 109 | 110 | template 111 | struct GenericStringRef; 112 | 113 | template 114 | class GenericValue; 115 | 116 | typedef GenericValue, MemoryPoolAllocator > Value; 117 | 118 | template 119 | class GenericDocument; 120 | 121 | typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; 122 | 123 | // pointer.h 124 | 125 | template 126 | class GenericPointer; 127 | 128 | typedef GenericPointer Pointer; 129 | 130 | // schema.h 131 | 132 | template 133 | class IGenericRemoteSchemaDocumentProvider; 134 | 135 | template 136 | class GenericSchemaDocument; 137 | 138 | typedef GenericSchemaDocument SchemaDocument; 139 | typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; 140 | 141 | template < 142 | typename SchemaDocumentType, 143 | typename OutputHandler, 144 | typename StateAllocator> 145 | class GenericSchemaValidator; 146 | 147 | typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; 148 | 149 | CEREAL_RAPIDJSON_NAMESPACE_END 150 | 151 | #endif // CEREAL_RAPIDJSON_RAPIDJSONFWD_H_ 152 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_IEEE754_ 16 | #define CEREAL_RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | CEREAL_RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static unsigned EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return static_cast(order) + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = CEREAL_RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = CEREAL_RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = CEREAL_RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = CEREAL_RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | CEREAL_RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // CEREAL_RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/internal/meta.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_META_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_META_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __GNUC__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | #if defined(_MSC_VER) 25 | CEREAL_RAPIDJSON_DIAG_PUSH 26 | CEREAL_RAPIDJSON_DIAG_OFF(6334) 27 | #endif 28 | 29 | #if CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS 30 | #include 31 | #endif 32 | 33 | //@cond CEREAL_RAPIDJSON_INTERNAL 34 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 35 | namespace internal { 36 | 37 | // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching 38 | template struct Void { typedef void Type; }; 39 | 40 | /////////////////////////////////////////////////////////////////////////////// 41 | // BoolType, TrueType, FalseType 42 | // 43 | template struct BoolType { 44 | static const bool Value = Cond; 45 | typedef BoolType Type; 46 | }; 47 | typedef BoolType TrueType; 48 | typedef BoolType FalseType; 49 | 50 | 51 | /////////////////////////////////////////////////////////////////////////////// 52 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr 53 | // 54 | 55 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; 56 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; 57 | template struct SelectIfCond : SelectIfImpl::template Apply {}; 58 | template struct SelectIf : SelectIfCond {}; 59 | 60 | template struct AndExprCond : FalseType {}; 61 | template <> struct AndExprCond : TrueType {}; 62 | template struct OrExprCond : TrueType {}; 63 | template <> struct OrExprCond : FalseType {}; 64 | 65 | template struct BoolExpr : SelectIf::Type {}; 66 | template struct NotExpr : SelectIf::Type {}; 67 | template struct AndExpr : AndExprCond::Type {}; 68 | template struct OrExpr : OrExprCond::Type {}; 69 | 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // AddConst, MaybeAddConst, RemoveConst 73 | template struct AddConst { typedef const T Type; }; 74 | template struct MaybeAddConst : SelectIfCond {}; 75 | template struct RemoveConst { typedef T Type; }; 76 | template struct RemoveConst { typedef T Type; }; 77 | 78 | 79 | /////////////////////////////////////////////////////////////////////////////// 80 | // IsSame, IsConst, IsMoreConst, IsPointer 81 | // 82 | template struct IsSame : FalseType {}; 83 | template struct IsSame : TrueType {}; 84 | 85 | template struct IsConst : FalseType {}; 86 | template struct IsConst : TrueType {}; 87 | 88 | template 89 | struct IsMoreConst 90 | : AndExpr::Type, typename RemoveConst::Type>, 91 | BoolType::Value >= IsConst::Value> >::Type {}; 92 | 93 | template struct IsPointer : FalseType {}; 94 | template struct IsPointer : TrueType {}; 95 | 96 | /////////////////////////////////////////////////////////////////////////////// 97 | // IsBaseOf 98 | // 99 | #if CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS 100 | 101 | template struct IsBaseOf 102 | : BoolType< ::std::is_base_of::value> {}; 103 | 104 | #else // simplified version adopted from Boost 105 | 106 | template struct IsBaseOfImpl { 107 | CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); 108 | CEREAL_RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); 109 | 110 | typedef char (&Yes)[1]; 111 | typedef char (&No) [2]; 112 | 113 | template 114 | static Yes Check(const D*, T); 115 | static No Check(const B*, int); 116 | 117 | struct Host { 118 | operator const B*() const; 119 | operator const D*(); 120 | }; 121 | 122 | enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; 123 | }; 124 | 125 | template struct IsBaseOf 126 | : OrExpr, BoolExpr > >::Type {}; 127 | 128 | #endif // CEREAL_RAPIDJSON_HAS_CXX11_TYPETRAITS 129 | 130 | 131 | ////////////////////////////////////////////////////////////////////////// 132 | // EnableIf / DisableIf 133 | // 134 | template struct EnableIfCond { typedef T Type; }; 135 | template struct EnableIfCond { /* empty */ }; 136 | 137 | template struct DisableIfCond { typedef T Type; }; 138 | template struct DisableIfCond { /* empty */ }; 139 | 140 | template 141 | struct EnableIf : EnableIfCond {}; 142 | 143 | template 144 | struct DisableIf : DisableIfCond {}; 145 | 146 | // SFINAE helpers 147 | struct SfinaeTag {}; 148 | template struct RemoveSfinaeTag; 149 | template struct RemoveSfinaeTag { typedef T Type; }; 150 | 151 | #define CEREAL_RAPIDJSON_REMOVEFPTR_(type) \ 152 | typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ 153 | < ::CEREAL_RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type 154 | 155 | #define CEREAL_RAPIDJSON_ENABLEIF(cond) \ 156 | typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::EnableIf \ 157 | ::Type * = NULL 158 | 159 | #define CEREAL_RAPIDJSON_DISABLEIF(cond) \ 160 | typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::DisableIf \ 161 | ::Type * = NULL 162 | 163 | #define CEREAL_RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 164 | typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::EnableIf \ 165 | ::Type 167 | 168 | #define CEREAL_RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 169 | typename ::CEREAL_RAPIDJSON_NAMESPACE::internal::DisableIf \ 170 | ::Type 172 | 173 | } // namespace internal 174 | CEREAL_RAPIDJSON_NAMESPACE_END 175 | //@endcond 176 | 177 | #if defined(__GNUC__) || defined(_MSC_VER) 178 | CEREAL_RAPIDJSON_DIAG_POP 179 | #endif 180 | 181 | #endif // CEREAL_RAPIDJSON_INTERNAL_META_H_ 182 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_POW10_ 16 | #define CEREAL_RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | CEREAL_RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | CEREAL_RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // CEREAL_RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Custom strlen() which works on different character types. 24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 25 | \param s Null-terminated input string. 26 | \return Number of characters in the string. 27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 28 | */ 29 | template 30 | inline SizeType StrLen(const Ch* s) { 31 | const Ch* p = s; 32 | while (*p) ++p; 33 | return SizeType(p - s); 34 | } 35 | 36 | //! Returns number of code points in a encoded string. 37 | template 38 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 39 | GenericStringStream is(s); 40 | const typename Encoding::Ch* end = s + length; 41 | SizeType count = 0; 42 | while (is.src_ < end) { 43 | unsigned codepoint; 44 | if (!Encoding::Decode(is, &codepoint)) 45 | return false; 46 | count++; 47 | } 48 | *outCount = count; 49 | return true; 50 | } 51 | 52 | } // namespace internal 53 | CEREAL_RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 56 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) CEREAL_RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | CEREAL_RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | CEREAL_RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | CEREAL_RAPIDJSON_DIAG_PUSH 28 | CEREAL_RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 29 | CEREAL_RAPIDJSON_DIAG_OFF(4127) // ignore assert(false) for triggering exception 30 | #endif 31 | 32 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 35 | /*! 36 | The classes can be wrapped including but not limited to: 37 | 38 | - \c std::istringstream 39 | - \c std::stringstream 40 | - \c std::wistringstream 41 | - \c std::wstringstream 42 | - \c std::ifstream 43 | - \c std::fstream 44 | - \c std::wifstream 45 | - \c std::wfstream 46 | 47 | \tparam StreamType Class derived from \c std::basic_istream. 48 | */ 49 | 50 | template 51 | class BasicIStreamWrapper { 52 | public: 53 | typedef typename StreamType::char_type Ch; 54 | BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} 55 | 56 | Ch Peek() const { 57 | typename StreamType::int_type c = stream_.peek(); 58 | return CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : '\0'; 59 | } 60 | 61 | Ch Take() { 62 | typename StreamType::int_type c = stream_.get(); 63 | if (CEREAL_RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { 64 | count_++; 65 | return static_cast(c); 66 | } 67 | else 68 | return '\0'; 69 | } 70 | 71 | // tellg() may return -1 when failed. So we count by ourself. 72 | size_t Tell() const { return count_; } 73 | 74 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 75 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 76 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 77 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 78 | 79 | // For encoding detection only. 80 | const Ch* Peek4() const { 81 | CEREAL_RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. 82 | int i; 83 | bool hasError = false; 84 | for (i = 0; i < 4; ++i) { 85 | typename StreamType::int_type c = stream_.get(); 86 | if (c == StreamType::traits_type::eof()) { 87 | hasError = true; 88 | stream_.clear(); 89 | break; 90 | } 91 | peekBuffer_[i] = static_cast(c); 92 | } 93 | for (--i; i >= 0; --i) 94 | stream_.putback(peekBuffer_[i]); 95 | return !hasError ? peekBuffer_ : 0; 96 | } 97 | 98 | private: 99 | BasicIStreamWrapper(const BasicIStreamWrapper&); 100 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 101 | 102 | StreamType& stream_; 103 | size_t count_; //!< Number of characters read. Note: 104 | mutable Ch peekBuffer_[4]; 105 | }; 106 | 107 | typedef BasicIStreamWrapper IStreamWrapper; 108 | typedef BasicIStreamWrapper WIStreamWrapper; 109 | 110 | #if defined(__clang__) || defined(_MSC_VER) 111 | CEREAL_RAPIDJSON_DIAG_POP 112 | #endif 113 | 114 | CEREAL_RAPIDJSON_NAMESPACE_END 115 | 116 | #endif // CEREAL_RAPIDJSON_ISTREAMWRAPPER_H_ 117 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | CEREAL_RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 23 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | #ifdef _MSC_VER 27 | CEREAL_RAPIDJSON_DIAG_PUSH 28 | CEREAL_RAPIDJSON_DIAG_OFF( 4127 ) // ignore assert(false) for triggering exception 29 | #endif 30 | 31 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | //! Represents an in-memory input byte stream. 34 | /*! 35 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 36 | 37 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 38 | 39 | Differences between MemoryStream and StringStream: 40 | 1. StringStream has encoding but MemoryStream is a byte stream. 41 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 42 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 43 | \note implements Stream concept 44 | */ 45 | struct MemoryStream { 46 | typedef char Ch; // byte 47 | 48 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 49 | 50 | Ch Peek() const { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 51 | Ch Take() { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 52 | size_t Tell() const { return static_cast(src_ - begin_); } 53 | 54 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 55 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 56 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 57 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 58 | 59 | // For encoding detection only. 60 | const Ch* Peek4() const { 61 | return Tell() + 4 <= size_ ? src_ : 0; 62 | } 63 | 64 | const Ch* src_; //!< Current read position. 65 | const Ch* begin_; //!< Original head of the string. 66 | const Ch* end_; //!< End of stream. 67 | size_t size_; //!< Size of the stream. 68 | }; 69 | 70 | CEREAL_RAPIDJSON_NAMESPACE_END 71 | 72 | #if defined(__clang__) || defined(_MSC_VER) 73 | CEREAL_RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 77 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | CEREAL_RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | CEREAL_RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/stream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "rapidjson.h" 16 | 17 | #ifndef CEREAL_RAPIDJSON_STREAM_H_ 18 | #define CEREAL_RAPIDJSON_STREAM_H_ 19 | 20 | #include "encodings.h" 21 | 22 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Stream 26 | 27 | /*! \class rapidjson::Stream 28 | \brief Concept for reading and writing characters. 29 | 30 | For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). 31 | 32 | For write-only stream, only need to implement Put() and Flush(). 33 | 34 | \code 35 | concept Stream { 36 | typename Ch; //!< Character type of the stream. 37 | 38 | //! Read the current character from stream without moving the read cursor. 39 | Ch Peek() const; 40 | 41 | //! Read the current character from stream and moving the read cursor to next character. 42 | Ch Take(); 43 | 44 | //! Get the current read cursor. 45 | //! \return Number of characters read from start. 46 | size_t Tell(); 47 | 48 | //! Begin writing operation at the current read pointer. 49 | //! \return The begin writer pointer. 50 | Ch* PutBegin(); 51 | 52 | //! Write a character. 53 | void Put(Ch c); 54 | 55 | //! Flush the buffer. 56 | void Flush(); 57 | 58 | //! End the writing operation. 59 | //! \param begin The begin write pointer returned by PutBegin(). 60 | //! \return Number of characters written. 61 | size_t PutEnd(Ch* begin); 62 | } 63 | \endcode 64 | */ 65 | 66 | //! Provides additional information for stream. 67 | /*! 68 | By using traits pattern, this type provides a default configuration for stream. 69 | For custom stream, this type can be specialized for other configuration. 70 | See TEST(Reader, CustomStringStream) in readertest.cpp for example. 71 | */ 72 | template 73 | struct StreamTraits { 74 | //! Whether to make local copy of stream for optimization during parsing. 75 | /*! 76 | By default, for safety, streams do not use local copy optimization. 77 | Stream that can be copied fast should specialize this, like StreamTraits. 78 | */ 79 | enum { copyOptimization = 0 }; 80 | }; 81 | 82 | //! Reserve n characters for writing to a stream. 83 | template 84 | inline void PutReserve(Stream& stream, size_t count) { 85 | (void)stream; 86 | (void)count; 87 | } 88 | 89 | //! Write character to a stream, presuming buffer is reserved. 90 | template 91 | inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { 92 | stream.Put(c); 93 | } 94 | 95 | //! Put N copies of a character to a stream. 96 | template 97 | inline void PutN(Stream& stream, Ch c, size_t n) { 98 | PutReserve(stream, n); 99 | for (size_t i = 0; i < n; i++) 100 | PutUnsafe(stream, c); 101 | } 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // StringStream 105 | 106 | //! Read-only string stream. 107 | /*! \note implements Stream concept 108 | */ 109 | template 110 | struct GenericStringStream { 111 | typedef typename Encoding::Ch Ch; 112 | 113 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 114 | 115 | Ch Peek() const { return *src_; } 116 | Ch Take() { return *src_++; } 117 | size_t Tell() const { return static_cast(src_ - head_); } 118 | 119 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 120 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 121 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 122 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 123 | 124 | const Ch* src_; //!< Current read position. 125 | const Ch* head_; //!< Original head of the string. 126 | }; 127 | 128 | template 129 | struct StreamTraits > { 130 | enum { copyOptimization = 1 }; 131 | }; 132 | 133 | //! String stream with UTF8 encoding. 134 | typedef GenericStringStream > StringStream; 135 | 136 | /////////////////////////////////////////////////////////////////////////////// 137 | // InsituStringStream 138 | 139 | //! A read-write string stream. 140 | /*! This string stream is particularly designed for in-situ parsing. 141 | \note implements Stream concept 142 | */ 143 | template 144 | struct GenericInsituStringStream { 145 | typedef typename Encoding::Ch Ch; 146 | 147 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 148 | 149 | // Read 150 | Ch Peek() { return *src_; } 151 | Ch Take() { return *src_++; } 152 | size_t Tell() { return static_cast(src_ - head_); } 153 | 154 | // Write 155 | void Put(Ch c) { CEREAL_RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 156 | 157 | Ch* PutBegin() { return dst_ = src_; } 158 | size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } 159 | void Flush() {} 160 | 161 | Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } 162 | void Pop(size_t count) { dst_ -= count; } 163 | 164 | Ch* src_; 165 | Ch* dst_; 166 | Ch* head_; 167 | }; 168 | 169 | template 170 | struct StreamTraits > { 171 | enum { copyOptimization = 1 }; 172 | }; 173 | 174 | //! Insitu string stream with UTF8 encoding. 175 | typedef GenericInsituStringStream > InsituStringStream; 176 | 177 | CEREAL_RAPIDJSON_NAMESPACE_END 178 | 179 | #endif // CEREAL_RAPIDJSON_STREAM_H_ 180 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_STRINGBUFFER_H_ 16 | #define CEREAL_RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | CEREAL_RAPIDJSON_DIAG_PUSH 29 | CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | size_t GetSize() const { return stack_.GetSize(); } 82 | 83 | static const size_t kDefaultCapacity = 256; 84 | mutable internal::Stack stack_; 85 | 86 | private: 87 | // Prohibit copy constructor & assignment operator. 88 | GenericStringBuffer(const GenericStringBuffer&); 89 | GenericStringBuffer& operator=(const GenericStringBuffer&); 90 | }; 91 | 92 | //! String buffer with UTF8 encoding 93 | typedef GenericStringBuffer > StringBuffer; 94 | 95 | template 96 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 97 | stream.Reserve(count); 98 | } 99 | 100 | template 101 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 102 | stream.PutUnsafe(c); 103 | } 104 | 105 | //! Implement specialized version of PutN() with memset() for better performance. 106 | template<> 107 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 108 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 109 | } 110 | 111 | CEREAL_RAPIDJSON_NAMESPACE_END 112 | 113 | #if defined(__clang__) 114 | CEREAL_RAPIDJSON_DIAG_POP 115 | #endif 116 | 117 | #endif // CEREAL_RAPIDJSON_STRINGBUFFER_H_ 118 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidxml/rapidxml_iterators.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CEREAL_RAPIDXML_ITERATORS_HPP_INCLUDED 2 | #define CEREAL_RAPIDXML_ITERATORS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | 8 | #include "rapidxml.hpp" 9 | 10 | namespace cereal { 11 | namespace rapidxml 12 | { 13 | 14 | //! Iterator of child nodes of xml_node 15 | template 16 | class node_iterator 17 | { 18 | 19 | public: 20 | 21 | typedef typename xml_node value_type; 22 | typedef typename xml_node &reference; 23 | typedef typename xml_node *pointer; 24 | typedef std::ptrdiff_t difference_type; 25 | typedef std::bidirectional_iterator_tag iterator_category; 26 | 27 | node_iterator() 28 | : m_node(0) 29 | { 30 | } 31 | 32 | node_iterator(xml_node *node) 33 | : m_node(node->first_node()) 34 | { 35 | } 36 | 37 | reference operator *() const 38 | { 39 | assert(m_node); 40 | return *m_node; 41 | } 42 | 43 | pointer operator->() const 44 | { 45 | assert(m_node); 46 | return m_node; 47 | } 48 | 49 | node_iterator& operator++() 50 | { 51 | assert(m_node); 52 | m_node = m_node->next_sibling(); 53 | return *this; 54 | } 55 | 56 | node_iterator operator++(int) 57 | { 58 | node_iterator tmp = *this; 59 | ++this; 60 | return tmp; 61 | } 62 | 63 | node_iterator& operator--() 64 | { 65 | assert(m_node && m_node->previous_sibling()); 66 | m_node = m_node->previous_sibling(); 67 | return *this; 68 | } 69 | 70 | node_iterator operator--(int) 71 | { 72 | node_iterator tmp = *this; 73 | ++this; 74 | return tmp; 75 | } 76 | 77 | bool operator ==(const node_iterator &rhs) 78 | { 79 | return m_node == rhs.m_node; 80 | } 81 | 82 | bool operator !=(const node_iterator &rhs) 83 | { 84 | return m_node != rhs.m_node; 85 | } 86 | 87 | private: 88 | 89 | xml_node *m_node; 90 | 91 | }; 92 | 93 | //! Iterator of child attributes of xml_node 94 | template 95 | class attribute_iterator 96 | { 97 | 98 | public: 99 | 100 | typedef typename xml_attribute value_type; 101 | typedef typename xml_attribute &reference; 102 | typedef typename xml_attribute *pointer; 103 | typedef std::ptrdiff_t difference_type; 104 | typedef std::bidirectional_iterator_tag iterator_category; 105 | 106 | attribute_iterator() 107 | : m_attribute(0) 108 | { 109 | } 110 | 111 | attribute_iterator(xml_node *node) 112 | : m_attribute(node->first_attribute()) 113 | { 114 | } 115 | 116 | reference operator *() const 117 | { 118 | assert(m_attribute); 119 | return *m_attribute; 120 | } 121 | 122 | pointer operator->() const 123 | { 124 | assert(m_attribute); 125 | return m_attribute; 126 | } 127 | 128 | attribute_iterator& operator++() 129 | { 130 | assert(m_attribute); 131 | m_attribute = m_attribute->next_attribute(); 132 | return *this; 133 | } 134 | 135 | attribute_iterator operator++(int) 136 | { 137 | attribute_iterator tmp = *this; 138 | ++this; 139 | return tmp; 140 | } 141 | 142 | attribute_iterator& operator--() 143 | { 144 | assert(m_attribute && m_attribute->previous_attribute()); 145 | m_attribute = m_attribute->previous_attribute(); 146 | return *this; 147 | } 148 | 149 | attribute_iterator operator--(int) 150 | { 151 | attribute_iterator tmp = *this; 152 | ++this; 153 | return tmp; 154 | } 155 | 156 | bool operator ==(const attribute_iterator &rhs) 157 | { 158 | return m_attribute == rhs.m_attribute; 159 | } 160 | 161 | bool operator !=(const attribute_iterator &rhs) 162 | { 163 | return m_attribute != rhs.m_attribute; 164 | } 165 | 166 | private: 167 | 168 | xml_attribute *m_attribute; 169 | 170 | }; 171 | 172 | } 173 | } // namespace cereal 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /third_party/cereal/external/rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 2 | #define CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 8 | 9 | #include "rapidxml.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace cereal { 16 | namespace rapidxml 17 | { 18 | 19 | //! Represents data loaded from a file 20 | template 21 | class file 22 | { 23 | 24 | public: 25 | 26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 27 | //! \param filename Filename to load. 28 | file(const char *filename) 29 | { 30 | using namespace std; 31 | 32 | // Open stream 33 | basic_ifstream stream(filename, ios::binary); 34 | if (!stream) 35 | throw runtime_error(string("cannot open file ") + filename); 36 | stream.unsetf(ios::skipws); 37 | 38 | // Determine stream size 39 | stream.seekg(0, ios::end); 40 | size_t size = stream.tellg(); 41 | stream.seekg(0); 42 | 43 | // Load data and add terminating 0 44 | m_data.resize(size + 1); 45 | stream.read(&m_data.front(), static_cast(size)); 46 | m_data[size] = 0; 47 | } 48 | 49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 50 | //! \param stream Stream to load from 51 | file(std::basic_istream &stream) 52 | { 53 | using namespace std; 54 | 55 | // Load data and add terminating 0 56 | stream.unsetf(ios::skipws); 57 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 58 | if (stream.fail() || stream.bad()) 59 | throw runtime_error("error reading stream"); 60 | m_data.push_back(0); 61 | } 62 | 63 | //! Gets file data. 64 | //! \return Pointer to data of file. 65 | Ch *data() 66 | { 67 | return &m_data.front(); 68 | } 69 | 70 | //! Gets file data. 71 | //! \return Pointer to data of file. 72 | const Ch *data() const 73 | { 74 | return &m_data.front(); 75 | } 76 | 77 | //! Gets file data size. 78 | //! \return Size of file data, in characters. 79 | std::size_t size() const 80 | { 81 | return m_data.size(); 82 | } 83 | 84 | private: 85 | 86 | std::vector m_data; // File data 87 | 88 | }; 89 | 90 | //! Counts children of node. Time complexity is O(n). 91 | //! \return Number of children of node 92 | template 93 | inline std::size_t count_children(xml_node *node) 94 | { 95 | xml_node *child = node->first_node(); 96 | std::size_t count = 0; 97 | while (child) 98 | { 99 | ++count; 100 | child = child->next_sibling(); 101 | } 102 | return count; 103 | } 104 | 105 | //! Counts attributes of node. Time complexity is O(n). 106 | //! \return Number of attributes of node 107 | template 108 | inline std::size_t count_attributes(xml_node *node) 109 | { 110 | xml_attribute *attr = node->first_attribute(); 111 | std::size_t count = 0; 112 | while (attr) 113 | { 114 | ++count; 115 | attr = attr->next_attribute(); 116 | } 117 | return count; 118 | } 119 | 120 | } 121 | } // namespace cereal 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /third_party/cereal/macros.hpp: -------------------------------------------------------------------------------- 1 | /*! \file macros.hpp 2 | \brief Preprocessor macros that can customise the cereal library 3 | 4 | By default, cereal looks for serialization functions with very 5 | specific names, that is: serialize, load, save, load_minimal, 6 | or save_minimal. 7 | 8 | This file allows an advanced user to change these names to conform 9 | to some other style or preference. This is implemented using 10 | preprocessor macros. 11 | 12 | As a result of this, in internal cereal code you will see macros 13 | used for these function names. In user code, you should name 14 | the functions like you normally would and not use the macros 15 | to improve readability. 16 | \ingroup utility */ 17 | /* 18 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | * Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | * Redistributions in binary form must reproduce the above copyright 26 | notice, this list of conditions and the following disclaimer in the 27 | documentation and/or other materials provided with the distribution. 28 | * Neither the name of cereal nor the 29 | names of its contributors may be used to endorse or promote products 30 | derived from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 36 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 37 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 39 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | */ 43 | 44 | #ifndef CEREAL_MACROS_HPP_ 45 | #define CEREAL_MACROS_HPP_ 46 | 47 | #ifndef CEREAL_THREAD_SAFE 48 | //! Whether cereal should be compiled for a threaded environment 49 | /*! This macro causes cereal to use mutexes to control access to 50 | global internal state in a thread safe manner. 51 | 52 | Note that even with this enabled you must still ensure that 53 | archives are accessed by only one thread at a time; it is safe 54 | to use multiple archives in paralel, but not to access one archive 55 | from many places simultaneously. */ 56 | #define CEREAL_THREAD_SAFE 0 57 | #endif // CEREAL_THREAD_SAFE 58 | 59 | // ###################################################################### 60 | #ifndef CEREAL_SERIALIZE_FUNCTION_NAME 61 | //! The serialization/deserialization function name to search for. 62 | /*! You can define @c CEREAL_SERIALIZE_FUNCTION_NAME to be different assuming 63 | you do so before this file is included. */ 64 | #define CEREAL_SERIALIZE_FUNCTION_NAME serialize 65 | #endif // CEREAL_SERIALIZE_FUNCTION_NAME 66 | 67 | #ifndef CEREAL_LOAD_FUNCTION_NAME 68 | //! The deserialization (load) function name to search for. 69 | /*! You can define @c CEREAL_LOAD_FUNCTION_NAME to be different assuming you do so 70 | before this file is included. */ 71 | #define CEREAL_LOAD_FUNCTION_NAME load 72 | #endif // CEREAL_LOAD_FUNCTION_NAME 73 | 74 | #ifndef CEREAL_SAVE_FUNCTION_NAME 75 | //! The serialization (save) function name to search for. 76 | /*! You can define @c CEREAL_SAVE_FUNCTION_NAME to be different assuming you do so 77 | before this file is included. */ 78 | #define CEREAL_SAVE_FUNCTION_NAME save 79 | #endif // CEREAL_SAVE_FUNCTION_NAME 80 | 81 | #ifndef CEREAL_LOAD_MINIMAL_FUNCTION_NAME 82 | //! The deserialization (load_minimal) function name to search for. 83 | /*! You can define @c CEREAL_LOAD_MINIMAL_FUNCTION_NAME to be different assuming you do so 84 | before this file is included. */ 85 | #define CEREAL_LOAD_MINIMAL_FUNCTION_NAME load_minimal 86 | #endif // CEREAL_LOAD_MINIMAL_FUNCTION_NAME 87 | 88 | #ifndef CEREAL_SAVE_MINIMAL_FUNCTION_NAME 89 | //! The serialization (save_minimal) function name to search for. 90 | /*! You can define @c CEREAL_SAVE_MINIMAL_FUNCTION_NAME to be different assuming you do so 91 | before this file is included. */ 92 | #define CEREAL_SAVE_MINIMAL_FUNCTION_NAME save_minimal 93 | #endif // CEREAL_SAVE_MINIMAL_FUNCTION_NAME 94 | 95 | // ###################################################################### 96 | //! Defines the CEREAL_NOEXCEPT macro to use instead of noexcept 97 | /*! If a compiler we support does not support noexcept, this macro 98 | will detect this and define CEREAL_NOEXCEPT as a no-op 99 | @internal */ 100 | #if !defined(CEREAL_HAS_NOEXCEPT) 101 | #if defined(__clang__) 102 | #if __has_feature(cxx_noexcept) 103 | #define CEREAL_HAS_NOEXCEPT 104 | #endif 105 | #else // NOT clang 106 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \ 107 | defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 108 | #define CEREAL_HAS_NOEXCEPT 109 | #endif // end GCC/MSVC check 110 | #endif // end NOT clang block 111 | 112 | #ifndef CEREAL_NOEXCEPT 113 | #ifdef CEREAL_HAS_NOEXCEPT 114 | #define CEREAL_NOEXCEPT noexcept 115 | #else 116 | #define CEREAL_NOEXCEPT 117 | #endif // end CEREAL_HAS_NOEXCEPT 118 | #endif // end !defined(CEREAL_HAS_NOEXCEPT) 119 | #endif // ifndef CEREAL_NOEXCEPT 120 | 121 | #endif // CEREAL_MACROS_HPP_ 122 | -------------------------------------------------------------------------------- /third_party/cereal/types/array.hpp: -------------------------------------------------------------------------------- 1 | /*! \file array.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ARRAY_HPP_ 31 | #define CEREAL_TYPES_ARRAY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::array primitive types 39 | //! using binary serialization, if supported 40 | template inline 41 | typename std::enable_if, Archive>::value 42 | && std::is_arithmetic::value, void>::type 43 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 44 | { 45 | ar( binary_data( array.data(), sizeof(array) ) ); 46 | } 47 | 48 | //! Loading for std::array primitive types 49 | //! using binary serialization, if supported 50 | template inline 51 | typename std::enable_if, Archive>::value 52 | && std::is_arithmetic::value, void>::type 53 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 54 | { 55 | ar( binary_data( array.data(), sizeof(array) ) ); 56 | } 57 | 58 | //! Saving for std::array all other types 59 | template inline 60 | typename std::enable_if, Archive>::value 61 | || !std::is_arithmetic::value, void>::type 62 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 63 | { 64 | for( auto const & i : array ) 65 | ar( i ); 66 | } 67 | 68 | //! Loading for std::array all other types 69 | template inline 70 | typename std::enable_if, Archive>::value 71 | || !std::is_arithmetic::value, void>::type 72 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 73 | { 74 | for( auto & i : array ) 75 | ar( i ); 76 | } 77 | } // namespace cereal 78 | 79 | #endif // CEREAL_TYPES_ARRAY_HPP_ 80 | -------------------------------------------------------------------------------- /third_party/cereal/types/bitset.hpp: -------------------------------------------------------------------------------- 1 | /*! \file bitset.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_BITSET_HPP_ 31 | #define CEREAL_TYPES_BITSET_HPP_ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace cereal 38 | { 39 | namespace bitset_detail 40 | { 41 | //! The type the bitset is encoded with 42 | /*! @internal */ 43 | enum class type : uint8_t 44 | { 45 | ulong, 46 | ullong, 47 | string, 48 | bits 49 | }; 50 | } 51 | 52 | //! Serializing (save) for std::bitset when BinaryData optimization supported 53 | template , Archive>::value> 55 | = traits::sfinae> inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::bitset const & bits ) 57 | { 58 | ar( CEREAL_NVP_("type", bitset_detail::type::bits) ); 59 | 60 | // Serialize 8 bit chunks 61 | std::uint8_t chunk = 0; 62 | std::uint8_t mask = 0x80; 63 | 64 | // Set each chunk using a rotating mask for the current bit 65 | for( std::size_t i = 0; i < N; ++i ) 66 | { 67 | if( bits[i] ) 68 | chunk |= mask; 69 | 70 | mask >>= 1; 71 | 72 | // output current chunk when mask is empty (8 bits) 73 | if( mask == 0 ) 74 | { 75 | ar( chunk ); 76 | chunk = 0; 77 | mask = 0x80; 78 | } 79 | } 80 | 81 | // serialize remainder, if it exists 82 | if( mask != 0x80 ) 83 | ar( chunk ); 84 | } 85 | 86 | //! Serializing (save) for std::bitset when BinaryData is not supported 87 | template , Archive>::value> 89 | = traits::sfinae> inline 90 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::bitset const & bits ) 91 | { 92 | try 93 | { 94 | auto const b = bits.to_ulong(); 95 | ar( CEREAL_NVP_("type", bitset_detail::type::ulong) ); 96 | ar( CEREAL_NVP_("data", b) ); 97 | } 98 | catch( std::overflow_error const & ) 99 | { 100 | try 101 | { 102 | auto const b = bits.to_ullong(); 103 | ar( CEREAL_NVP_("type", bitset_detail::type::ullong) ); 104 | ar( CEREAL_NVP_("data", b) ); 105 | } 106 | catch( std::overflow_error const & ) 107 | { 108 | ar( CEREAL_NVP_("type", bitset_detail::type::string) ); 109 | ar( CEREAL_NVP_("data", bits.to_string()) ); 110 | } 111 | } 112 | } 113 | 114 | //! Serializing (load) for std::bitset 115 | template inline 116 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::bitset & bits ) 117 | { 118 | bitset_detail::type t; 119 | ar( CEREAL_NVP_("type", t) ); 120 | 121 | switch( t ) 122 | { 123 | case bitset_detail::type::ulong: 124 | { 125 | unsigned long b; 126 | ar( CEREAL_NVP_("data", b) ); 127 | bits = std::bitset( b ); 128 | break; 129 | } 130 | case bitset_detail::type::ullong: 131 | { 132 | unsigned long long b; 133 | ar( CEREAL_NVP_("data", b) ); 134 | bits = std::bitset( b ); 135 | break; 136 | } 137 | case bitset_detail::type::string: 138 | { 139 | std::string b; 140 | ar( CEREAL_NVP_("data", b) ); 141 | bits = std::bitset( b ); 142 | break; 143 | } 144 | case bitset_detail::type::bits: 145 | { 146 | // Normally we would use BinaryData to route this at compile time, 147 | // but doing this at runtime doesn't break any old serialization 148 | std::uint8_t chunk = 0; 149 | std::uint8_t mask = 0; 150 | 151 | // Load one chunk at a time, rotating through the chunk 152 | // to set bits in the bitset 153 | for( std::size_t i = 0; i < N; ++i ) 154 | { 155 | if( mask == 0 ) 156 | { 157 | ar( chunk ); 158 | mask = 0x80; 159 | } 160 | 161 | if( chunk & mask ) 162 | bits[i] = 1; 163 | 164 | mask >>= 1; 165 | } 166 | break; 167 | } 168 | default: 169 | throw Exception("Invalid bitset data representation"); 170 | } 171 | } 172 | } // namespace cereal 173 | 174 | #endif // CEREAL_TYPES_BITSET_HPP_ 175 | -------------------------------------------------------------------------------- /third_party/cereal/types/boost_variant.hpp: -------------------------------------------------------------------------------- 1 | /*! \file boost_variant.hpp 2 | \brief Support for boost::variant 3 | \ingroup OtherTypes */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_BOOST_VARIANT_HPP_ 31 | #define CEREAL_TYPES_BOOST_VARIANT_HPP_ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace cereal 38 | { 39 | namespace variant_detail 40 | { 41 | //! @internal 42 | template 43 | struct variant_save_visitor : boost::static_visitor<> 44 | { 45 | variant_save_visitor(Archive & ar_) : ar(ar_) {} 46 | 47 | template 48 | void operator()(T const & value) const 49 | { 50 | ar( CEREAL_NVP_("data", value) ); 51 | } 52 | 53 | Archive & ar; 54 | }; 55 | 56 | //! @internal 57 | template 58 | typename std::enable_if::value, void>::type 59 | load_variant(Archive & /*ar*/, int /*target*/, Variant & /*variant*/) 60 | { 61 | throw ::cereal::Exception("Error traversing variant during load"); 62 | } 63 | 64 | //! @internal 65 | template 66 | typename std::enable_if::value, void>::type 67 | load_variant(Archive & ar, int target, Variant & variant) 68 | { 69 | if(N == target) 70 | { 71 | H value; 72 | ar( CEREAL_NVP_("data", value) ); 73 | variant = value; 74 | } 75 | else 76 | load_variant(ar, target, variant); 77 | } 78 | 79 | } // namespace variant_detail 80 | 81 | //! Saving for boost::variant 82 | template inline 83 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, boost::variant const & variant ) 84 | { 85 | int32_t which = variant.which(); 86 | ar( CEREAL_NVP_("which", which) ); 87 | variant_detail::variant_save_visitor visitor(ar); 88 | variant.apply_visitor(visitor); 89 | } 90 | 91 | //! Loading for boost::variant 92 | template inline 93 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, boost::variant & variant ) 94 | { 95 | typedef typename boost::variant::types types; 96 | 97 | int32_t which; 98 | ar( CEREAL_NVP_("which", which) ); 99 | if(which >= boost::mpl::size::value) 100 | throw Exception("Invalid 'which' selector when deserializing boost::variant"); 101 | 102 | variant_detail::load_variant<0, boost::variant, VariantType1, VariantTypes...>(ar, which, variant); 103 | } 104 | } // namespace cereal 105 | 106 | #endif // CEREAL_TYPES_BOOST_VARIANT_HPP_ 107 | -------------------------------------------------------------------------------- /third_party/cereal/types/chrono.hpp: -------------------------------------------------------------------------------- 1 | /*! \file chrono.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_CHRONO_HPP_ 31 | #define CEREAL_TYPES_CHRONO_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving std::chrono::duration 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration const & dur ) 40 | { 41 | ar( CEREAL_NVP_("count", dur.count()) ); 42 | } 43 | 44 | //! Loading std::chrono::duration 45 | template inline 46 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration & dur ) 47 | { 48 | R count; 49 | ar( CEREAL_NVP_("count", count) ); 50 | 51 | dur = std::chrono::duration{count}; 52 | } 53 | 54 | //! Saving std::chrono::time_point 55 | template inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point const & dur ) 57 | { 58 | ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) ); 59 | } 60 | 61 | //! Loading std::chrono::time_point 62 | template inline 63 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point & dur ) 64 | { 65 | D elapsed; 66 | ar( CEREAL_NVP_("time_since_epoch", elapsed) ); 67 | 68 | dur = std::chrono::time_point{elapsed}; 69 | } 70 | } // namespace cereal 71 | 72 | #endif // CEREAL_TYPES_CHRONO_HPP_ 73 | -------------------------------------------------------------------------------- /third_party/cereal/types/common.hpp: -------------------------------------------------------------------------------- 1 | /*! \file common.hpp 2 | \brief Support common types - always included automatically 3 | \ingroup OtherTypes */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMMON_HPP_ 31 | #define CEREAL_TYPES_COMMON_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | namespace common_detail 38 | { 39 | //! Serialization for arrays if BinaryData is supported and we are arithmetic 40 | /*! @internal */ 41 | template inline 42 | void serializeArray( Archive & ar, T & array, std::true_type /* binary_supported */ ) 43 | { 44 | ar( binary_data( array, sizeof(array) ) ); 45 | } 46 | 47 | //! Serialization for arrays if BinaryData is not supported or we are not arithmetic 48 | /*! @internal */ 49 | template inline 50 | void serializeArray( Archive & ar, T & array, std::false_type /* binary_supported */ ) 51 | { 52 | for( auto & i : array ) 53 | ar( i ); 54 | } 55 | 56 | namespace 57 | { 58 | //! Gets the underlying type of an enum 59 | /*! @internal */ 60 | template 61 | struct enum_underlying_type : std::false_type {}; 62 | 63 | //! Gets the underlying type of an enum 64 | /*! Specialization for when we actually have an enum 65 | @internal */ 66 | template 67 | struct enum_underlying_type { using type = typename std::underlying_type::type; }; 68 | } // anon namespace 69 | 70 | //! Checks if a type is an enum 71 | /*! This is needed over simply calling std::is_enum because the type 72 | traits checking at compile time will attempt to call something like 73 | load_minimal with a special NoConvertRef struct that wraps up the true type. 74 | 75 | This will strip away any of that and also expose the true underlying type. 76 | @internal */ 77 | template 78 | class is_enum 79 | { 80 | private: 81 | using DecayedT = typename std::decay::type; 82 | using StrippedT = typename ::cereal::traits::strip_minimal::type; 83 | 84 | public: 85 | static const bool value = std::is_enum::value; 86 | using type = StrippedT; 87 | using base_type = typename enum_underlying_type::type; 88 | }; 89 | } 90 | 91 | //! Saving for enum types 92 | template inline 93 | typename std::enable_if::value, 94 | typename common_detail::is_enum::base_type>::type 95 | CEREAL_SAVE_MINIMAL_FUNCTION_NAME( Archive const &, T const & t ) 96 | { 97 | return static_cast::base_type>(t); 98 | } 99 | 100 | //! Loading for enum types 101 | template inline 102 | typename std::enable_if::value, void>::type 103 | CEREAL_LOAD_MINIMAL_FUNCTION_NAME( Archive const &, T && t, 104 | typename common_detail::is_enum::base_type const & value ) 105 | { 106 | t = reinterpret_cast::type const &>( value ); 107 | } 108 | 109 | //! Serialization for raw pointers 110 | /*! This exists only to throw a static_assert to let users know we don't support raw pointers. */ 111 | template inline 112 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive &, T * & ) 113 | { 114 | static_assert(cereal::traits::detail::delay_static_assert::value, 115 | "Cereal does not support serializing raw pointers - please use a smart pointer"); 116 | } 117 | 118 | //! Serialization for C style arrays 119 | template inline 120 | typename std::enable_if::value, void>::type 121 | CEREAL_SERIALIZE_FUNCTION_NAME(Archive & ar, T & array) 122 | { 123 | common_detail::serializeArray( ar, array, 124 | std::integral_constant, Archive>::value && 125 | std::is_arithmetic::type>::value>() ); 126 | } 127 | } // namespace cereal 128 | 129 | #endif // CEREAL_TYPES_COMMON_HPP_ 130 | -------------------------------------------------------------------------------- /third_party/cereal/types/complex.hpp: -------------------------------------------------------------------------------- 1 | /*! \file complex.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMPLEX_HPP_ 31 | #define CEREAL_TYPES_COMPLEX_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Serializing (save) for std::complex 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::complex const & comp ) 40 | { 41 | ar( CEREAL_NVP_("real", comp.real()), 42 | CEREAL_NVP_("imag", comp.imag()) ); 43 | } 44 | 45 | //! Serializing (load) for std::complex 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::complex & bits ) 48 | { 49 | T real, imag; 50 | ar( CEREAL_NVP_("real", real), 51 | CEREAL_NVP_("imag", imag) ); 52 | bits = {real, imag}; 53 | } 54 | } // namespace cereal 55 | 56 | #endif // CEREAL_TYPES_COMPLEX_HPP_ 57 | -------------------------------------------------------------------------------- /third_party/cereal/types/concepts/pair_associative_container.hpp: -------------------------------------------------------------------------------- 1 | /*! \file pair_associative_container.hpp 2 | \brief Support for the PairAssociativeContainer refinement of the 3 | AssociativeContainer concept. 4 | \ingroup TypeConcepts */ 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of cereal nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 32 | #define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 33 | 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std-like pair associative containers 39 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map const & map ) 41 | { 42 | ar( make_size_tag( static_cast(map.size()) ) ); 43 | 44 | for( const auto & i : map ) 45 | ar( make_map_item(i.first, i.second) ); 46 | } 47 | 48 | //! Loading for std-like pair associative containers 49 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map & map ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | map.clear(); 56 | 57 | auto hint = map.begin(); 58 | for( size_t i = 0; i < size; ++i ) 59 | { 60 | typename Map::key_type key; 61 | typename Map::mapped_type value; 62 | 63 | ar( make_map_item(key, value) ); 64 | #ifdef CEREAL_OLDER_GCC 65 | hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); 66 | #else // NOT CEREAL_OLDER_GCC 67 | hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); 68 | #endif // NOT CEREAL_OLDER_GCC 69 | } 70 | } 71 | } // namespace cereal 72 | 73 | #endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 74 | -------------------------------------------------------------------------------- /third_party/cereal/types/deque.hpp: -------------------------------------------------------------------------------- 1 | /*! \file deque.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_DEQUE_HPP_ 31 | #define CEREAL_TYPES_DEQUE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::deque 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::deque const & deque ) 41 | { 42 | ar( make_size_tag( static_cast(deque.size()) ) ); 43 | 44 | for( auto const & i : deque ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::deque 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::deque & deque ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | deque.resize( static_cast( size ) ); 56 | 57 | for( auto & i : deque ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_DEQUE_HPP_ 63 | -------------------------------------------------------------------------------- /third_party/cereal/types/forward_list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file forward_list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FORWARD_LIST_HPP_ 31 | #define CEREAL_TYPES_FORWARD_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::forward_list all other types 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::forward_list const & forward_list ) 41 | { 42 | // write the size - note that this is slow because we need to traverse 43 | // the entire list. there are ways we could avoid this but this was chosen 44 | // since it works in the most general fashion with any archive type 45 | size_type const size = std::distance( forward_list.begin(), forward_list.end() ); 46 | 47 | ar( make_size_tag( size ) ); 48 | 49 | // write the list 50 | for( const auto & i : forward_list ) 51 | ar( i ); 52 | } 53 | 54 | //! Loading for std::forward_list all other types from 55 | template 56 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::forward_list & forward_list ) 57 | { 58 | size_type size; 59 | ar( make_size_tag( size ) ); 60 | 61 | forward_list.resize( static_cast( size ) ); 62 | 63 | for( auto & i : forward_list ) 64 | ar( i ); 65 | } 66 | } // namespace cereal 67 | 68 | #endif // CEREAL_TYPES_FORWARD_LIST_HPP_ 69 | -------------------------------------------------------------------------------- /third_party/cereal/types/functional.hpp: -------------------------------------------------------------------------------- 1 | /*! \file functional.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2016, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FUNCTIONAL_HPP_ 31 | #define CEREAL_TYPES_FUNCTIONAL_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving for std::less 38 | template inline 39 | void serialize( Archive &, std::less & ) 40 | { } 41 | } // namespace cereal 42 | 43 | #endif // CEREAL_TYPES_FUNCTIONAL_HPP_ 44 | -------------------------------------------------------------------------------- /third_party/cereal/types/list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_LIST_HPP_ 31 | #define CEREAL_TYPES_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::list 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list const & list ) 41 | { 42 | ar( make_size_tag( static_cast(list.size()) ) ); 43 | 44 | for( auto const & i : list ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::list 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list & list ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | list.resize( static_cast( size ) ); 56 | 57 | for( auto & i : list ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_LIST_HPP_ 63 | -------------------------------------------------------------------------------- /third_party/cereal/types/map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_MAP_HPP_ 31 | #define CEREAL_TYPES_MAP_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #endif // CEREAL_TYPES_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /third_party/cereal/types/queue.hpp: -------------------------------------------------------------------------------- 1 | /*! \file queue.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_QUEUE_HPP_ 31 | #define CEREAL_TYPES_QUEUE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | // The default container for queue is deque, so let's include that too 37 | #include 38 | // The default comparator for queue is less 39 | #include 40 | 41 | namespace cereal 42 | { 43 | namespace queue_detail 44 | { 45 | //! Allows access to the protected container in queue 46 | /*! @internal */ 47 | template inline 48 | C const & container( std::queue const & queue ) 49 | { 50 | struct H : public std::queue 51 | { 52 | static C const & get( std::queue const & q ) 53 | { 54 | return q.*(&H::c); 55 | } 56 | }; 57 | 58 | return H::get( queue ); 59 | } 60 | 61 | //! Allows access to the protected container in priority queue 62 | /*! @internal */ 63 | template inline 64 | C const & container( std::priority_queue const & priority_queue ) 65 | { 66 | struct H : public std::priority_queue 67 | { 68 | static C const & get( std::priority_queue const & pq ) 69 | { 70 | return pq.*(&H::c); 71 | } 72 | }; 73 | 74 | return H::get( priority_queue ); 75 | } 76 | 77 | //! Allows access to the protected comparator in priority queue 78 | /*! @internal */ 79 | template inline 80 | Comp const & comparator( std::priority_queue const & priority_queue ) 81 | { 82 | struct H : public std::priority_queue 83 | { 84 | static Comp const & get( std::priority_queue const & pq ) 85 | { 86 | return pq.*(&H::comp); 87 | } 88 | }; 89 | 90 | return H::get( priority_queue ); 91 | } 92 | } 93 | 94 | //! Saving for std::queue 95 | template inline 96 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::queue const & queue ) 97 | { 98 | ar( CEREAL_NVP_("container", queue_detail::container( queue )) ); 99 | } 100 | 101 | //! Loading for std::queue 102 | template inline 103 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::queue & queue ) 104 | { 105 | C container; 106 | ar( CEREAL_NVP_("container", container) ); 107 | queue = std::queue( std::move( container ) ); 108 | } 109 | 110 | //! Saving for std::priority_queue 111 | template inline 112 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::priority_queue const & priority_queue ) 113 | { 114 | ar( CEREAL_NVP_("comparator", queue_detail::comparator( priority_queue )) ); 115 | ar( CEREAL_NVP_("container", queue_detail::container( priority_queue )) ); 116 | } 117 | 118 | //! Loading for std::priority_queue 119 | template inline 120 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::priority_queue & priority_queue ) 121 | { 122 | Comp comparator; 123 | ar( CEREAL_NVP_("comparator", comparator) ); 124 | 125 | C container; 126 | ar( CEREAL_NVP_("container", container) ); 127 | 128 | priority_queue = std::priority_queue( comparator, std::move( container ) ); 129 | } 130 | } // namespace cereal 131 | 132 | #endif // CEREAL_TYPES_QUEUE_HPP_ 133 | -------------------------------------------------------------------------------- /third_party/cereal/types/set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_SET_HPP_ 31 | #define CEREAL_TYPES_SET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | 59 | auto hint = set.begin(); 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | #ifdef CEREAL_OLDER_GCC 66 | hint = set.insert( hint, std::move( key ) ); 67 | #else // NOT CEREAL_OLDER_GCC 68 | hint = set.emplace_hint( hint, std::move( key ) ); 69 | #endif // NOT CEREAL_OLDER_GCC 70 | } 71 | } 72 | } 73 | 74 | //! Saving for std::set 75 | template inline 76 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::set const & set ) 77 | { 78 | set_detail::save( ar, set ); 79 | } 80 | 81 | //! Loading for std::set 82 | template inline 83 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::set & set ) 84 | { 85 | set_detail::load( ar, set ); 86 | } 87 | 88 | //! Saving for std::multiset 89 | template inline 90 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::multiset const & multiset ) 91 | { 92 | set_detail::save( ar, multiset ); 93 | } 94 | 95 | //! Loading for std::multiset 96 | template inline 97 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::multiset & multiset ) 98 | { 99 | set_detail::load( ar, multiset ); 100 | } 101 | } // namespace cereal 102 | 103 | #endif // CEREAL_TYPES_SET_HPP_ 104 | -------------------------------------------------------------------------------- /third_party/cereal/types/stack.hpp: -------------------------------------------------------------------------------- 1 | /*! \file stack.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STACK_HPP_ 31 | #define CEREAL_TYPES_STACK_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | // The default container for stack is deque, so let's include that too 37 | #include 38 | 39 | namespace cereal 40 | { 41 | namespace stack_detail 42 | { 43 | //! Allows access to the protected container in stack 44 | template inline 45 | C const & container( std::stack const & stack ) 46 | { 47 | struct H : public std::stack 48 | { 49 | static C const & get( std::stack const & s ) 50 | { 51 | return s.*(&H::c); 52 | } 53 | }; 54 | 55 | return H::get( stack ); 56 | } 57 | } 58 | 59 | //! Saving for std::stack 60 | template inline 61 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::stack const & stack ) 62 | { 63 | ar( CEREAL_NVP_("container", stack_detail::container( stack )) ); 64 | } 65 | 66 | //! Loading for std::stack 67 | template inline 68 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::stack & stack ) 69 | { 70 | C container; 71 | ar( CEREAL_NVP_("container", container) ); 72 | stack = std::stack( std::move( container ) ); 73 | } 74 | } // namespace cereal 75 | 76 | #endif // CEREAL_TYPES_STACK_HPP_ 77 | -------------------------------------------------------------------------------- /third_party/cereal/types/string.hpp: -------------------------------------------------------------------------------- 1 | /*! \file string.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STRING_HPP_ 31 | #define CEREAL_TYPES_STRING_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for basic_string types, if binary data is supported 39 | template inline 40 | typename std::enable_if, Archive>::value, void>::type 41 | CEREAL_SAVE_FUNCTION_NAME(Archive & ar, std::basic_string const & str) 42 | { 43 | // Save number of chars + the data 44 | ar( make_size_tag( static_cast(str.size()) ) ); 45 | ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); 46 | } 47 | 48 | //! Serialization for basic_string types, if binary data is supported 49 | template inline 50 | typename std::enable_if, Archive>::value, void>::type 51 | CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string & str) 52 | { 53 | size_type size; 54 | ar( make_size_tag( size ) ); 55 | str.resize(static_cast(size)); 56 | ar( binary_data( const_cast( str.data() ), static_cast(size) * sizeof(CharT) ) ); 57 | } 58 | } // namespace cereal 59 | 60 | #endif // CEREAL_TYPES_STRING_HPP_ 61 | 62 | -------------------------------------------------------------------------------- /third_party/cereal/types/tuple.hpp: -------------------------------------------------------------------------------- 1 | /*! \file tuple.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_TUPLE_HPP_ 31 | #define CEREAL_TYPES_TUPLE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace tuple_detail 39 | { 40 | //! Creates a c string from a sequence of characters 41 | /*! The c string created will alwas be prefixed by "tuple_element" 42 | Based on code from: http://stackoverflow/a/20973438/710791 43 | @internal */ 44 | template 45 | struct char_seq_to_c_str 46 | { 47 | static const int size = 14;// Size of array for the word: tuple_element 48 | typedef const char (&arr_type)[sizeof...(Cs) + size]; 49 | static const char str[sizeof...(Cs) + size]; 50 | }; 51 | 52 | // the word tuple_element plus a number 53 | //! @internal 54 | template 55 | const char char_seq_to_c_str::str[sizeof...(Cs) + size] = 56 | {'t','u','p','l','e','_','e','l','e','m','e','n','t', Cs..., '\0'}; 57 | 58 | //! Converts a number into a sequence of characters 59 | /*! @tparam Q The quotient of dividing the original number by 10 60 | @tparam R The remainder of dividing the original number by 10 61 | @tparam C The sequence built so far 62 | @internal */ 63 | template 64 | struct to_string_impl 65 | { 66 | using type = typename to_string_impl::type; 67 | }; 68 | 69 | //! Base case with no quotient 70 | /*! @internal */ 71 | template 72 | struct to_string_impl<0, R, C...> 73 | { 74 | using type = char_seq_to_c_str; 75 | }; 76 | 77 | //! Generates a c string for a given index of a tuple 78 | /*! Example use: 79 | @code{cpp} 80 | tuple_element_name<3>::c_str();// returns "tuple_element3" 81 | @endcode 82 | @internal */ 83 | template 84 | struct tuple_element_name 85 | { 86 | using type = typename to_string_impl::type; 87 | static const typename type::arr_type c_str(){ return type::str; }; 88 | }; 89 | 90 | // unwinds a tuple to save it 91 | //! @internal 92 | template 93 | struct serialize 94 | { 95 | template inline 96 | static void apply( Archive & ar, std::tuple & tuple ) 97 | { 98 | serialize::template apply( ar, tuple ); 99 | ar( CEREAL_NVP_(tuple_element_name::c_str(), 100 | std::get( tuple )) ); 101 | } 102 | }; 103 | 104 | // Zero height specialization - nothing to do here 105 | //! @internal 106 | template <> 107 | struct serialize<0> 108 | { 109 | template inline 110 | static void apply( Archive &, std::tuple & ) 111 | { } 112 | }; 113 | } 114 | 115 | //! Serializing for std::tuple 116 | template inline 117 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::tuple & tuple ) 118 | { 119 | tuple_detail::serialize>::value>::template apply( ar, tuple ); 120 | } 121 | } // namespace cereal 122 | 123 | #endif // CEREAL_TYPES_TUPLE_HPP_ 124 | -------------------------------------------------------------------------------- /third_party/cereal/types/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_MAP_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #endif // CEREAL_TYPES_UNORDERED_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /third_party/cereal/types/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_SET_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_SET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace unordered_set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | set.reserve( static_cast( size ) ); 59 | 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | set.emplace( std::move( key ) ); 66 | } 67 | } 68 | } 69 | 70 | //! Saving for std::unordered_set 71 | template inline 72 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_set const & unordered_set ) 73 | { 74 | unordered_set_detail::save( ar, unordered_set ); 75 | } 76 | 77 | //! Loading for std::unordered_set 78 | template inline 79 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_set & unordered_set ) 80 | { 81 | unordered_set_detail::load( ar, unordered_set ); 82 | } 83 | 84 | //! Saving for std::unordered_multiset 85 | template inline 86 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_multiset const & unordered_multiset ) 87 | { 88 | unordered_set_detail::save( ar, unordered_multiset ); 89 | } 90 | 91 | //! Loading for std::unordered_multiset 92 | template inline 93 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_multiset & unordered_multiset ) 94 | { 95 | unordered_set_detail::load( ar, unordered_multiset ); 96 | } 97 | } // namespace cereal 98 | 99 | #endif // CEREAL_TYPES_UNORDERED_SET_HPP_ 100 | -------------------------------------------------------------------------------- /third_party/cereal/types/utility.hpp: -------------------------------------------------------------------------------- 1 | /*! \file utility.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UTILITY_HPP_ 31 | #define CEREAL_TYPES_UTILITY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing for std::pair 39 | template inline 40 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::pair & pair ) 41 | { 42 | ar( CEREAL_NVP_("first", pair.first), 43 | CEREAL_NVP_("second", pair.second) ); 44 | } 45 | } // namespace cereal 46 | 47 | #endif // CEREAL_TYPES_UTILITY_HPP_ 48 | -------------------------------------------------------------------------------- /third_party/cereal/types/valarray.hpp: -------------------------------------------------------------------------------- 1 | /*! \file valarray.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of cereal nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef CEREAL_TYPES_VALARRAY_HPP_ 33 | #define CEREAL_TYPES_VALARRAY_HPP_ 34 | 35 | #include 36 | #include 37 | 38 | namespace cereal 39 | { 40 | //! Saving for std::valarray arithmetic types, using binary serialization, if supported 41 | template inline 42 | typename std::enable_if, Archive>::value 43 | && std::is_arithmetic::value, void>::type 44 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 45 | { 46 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 47 | ar( binary_data( &valarray[0], valarray.size() * sizeof(T) ) ); // &valarray[0] ok since guaranteed contiguous 48 | } 49 | 50 | //! Loading for std::valarray arithmetic types, using binary serialization, if supported 51 | template inline 52 | typename std::enable_if, Archive>::value 53 | && std::is_arithmetic::value, void>::type 54 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 55 | { 56 | size_type valarraySize; 57 | ar( make_size_tag( valarraySize ) ); 58 | 59 | valarray.resize( static_cast( valarraySize ) ); 60 | ar( binary_data( &valarray[0], static_cast( valarraySize ) * sizeof(T) ) ); 61 | } 62 | 63 | //! Saving for std::valarray all other types 64 | template inline 65 | typename std::enable_if, Archive>::value 66 | || !std::is_arithmetic::value, void>::type 67 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 68 | { 69 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 70 | for(auto && v : valarray) 71 | ar(v); 72 | } 73 | 74 | //! Loading for std::valarray all other types 75 | template inline 76 | typename std::enable_if, Archive>::value 77 | || !std::is_arithmetic::value, void>::type 78 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 79 | { 80 | size_type valarraySize; 81 | ar( make_size_tag( valarraySize ) ); 82 | 83 | valarray.resize( static_cast( valarraySize ) ); 84 | for(auto && v : valarray) 85 | ar(v); 86 | } 87 | } // namespace cereal 88 | 89 | #endif // CEREAL_TYPES_VALARRAY_HPP_ 90 | -------------------------------------------------------------------------------- /third_party/cereal/types/vector.hpp: -------------------------------------------------------------------------------- 1 | /*! \file vector.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_VECTOR_HPP_ 31 | #define CEREAL_TYPES_VECTOR_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported 39 | template inline 40 | typename std::enable_if, Archive>::value 41 | && std::is_arithmetic::value && !std::is_same::value, void>::type 42 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::vector const & vector ) 43 | { 44 | ar( make_size_tag( static_cast(vector.size()) ) ); // number of elements 45 | ar( binary_data( vector.data(), vector.size() * sizeof(T) ) ); 46 | } 47 | 48 | //! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported 49 | template inline 50 | typename std::enable_if, Archive>::value 51 | && std::is_arithmetic::value && !std::is_same::value, void>::type 52 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::vector & vector ) 53 | { 54 | size_type vectorSize; 55 | ar( make_size_tag( vectorSize ) ); 56 | 57 | vector.resize( static_cast( vectorSize ) ); 58 | ar( binary_data( vector.data(), static_cast( vectorSize ) * sizeof(T) ) ); 59 | } 60 | 61 | //! Serialization for non-arithmetic vector types 62 | template inline 63 | typename std::enable_if, Archive>::value 64 | || !std::is_arithmetic::value, void>::type 65 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::vector const & vector ) 66 | { 67 | ar( make_size_tag( static_cast(vector.size()) ) ); // number of elements 68 | for(auto && v : vector) 69 | ar( v ); 70 | } 71 | 72 | //! Serialization for non-arithmetic vector types 73 | template inline 74 | typename std::enable_if, Archive>::value 75 | || !std::is_arithmetic::value, void>::type 76 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::vector & vector ) 77 | { 78 | size_type size; 79 | ar( make_size_tag( size ) ); 80 | 81 | vector.resize( static_cast( size ) ); 82 | for(auto && v : vector) 83 | ar( v ); 84 | } 85 | 86 | //! Serialization for bool vector types 87 | template inline 88 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::vector const & vector ) 89 | { 90 | ar( make_size_tag( static_cast(vector.size()) ) ); // number of elements 91 | for(auto && v : vector) 92 | ar( static_cast(v) ); 93 | } 94 | 95 | //! Serialization for bool vector types 96 | template inline 97 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::vector & vector ) 98 | { 99 | size_type size; 100 | ar( make_size_tag( size ) ); 101 | 102 | vector.resize( static_cast( size ) ); 103 | for(auto && v : vector) 104 | { 105 | bool b; 106 | ar( b ); 107 | v = b; 108 | } 109 | } 110 | } // namespace cereal 111 | 112 | #endif // CEREAL_TYPES_VECTOR_HPP_ 113 | --------------------------------------------------------------------------------