Ariles
writer_compact.cpp
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @copyright 2017-2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
9  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
10 
11  @brief
12 */
13 
14 #include <msgpack.hpp>
16 
17 namespace ariles2
18 {
19  namespace ns_msgpack_compact
20  {
21  namespace impl
22  {
24  {
25  public:
26  using PackerPtr = std::shared_ptr<::msgpack::packer<std::ostream>>;
27 
28 
29  public:
31 
32  public:
33  Writer(const Writer &) = delete;
34  void operator=(const Writer &) = delete;
35 
36 
37  template <class... t_Args>
38  explicit Writer(t_Args &&...args) : FileVisitorImplementation(std::forward<t_Args>(args)...)
39  {
40  packer_ = std::make_shared<::msgpack::packer<std::ostream>>(*output_stream_);
41  }
42  };
43  } // namespace impl
44  } // namespace ns_msgpack_compact
45 } // namespace ariles2
46 
47 
48 namespace ariles2
49 {
50  namespace ns_msgpack_compact
51  {
52  Writer::Writer(const std::string &file_name)
53  {
54  makeImplPtr(file_name);
55  }
56 
57 
58  Writer::Writer(std::ostream &output_stream)
59  {
60  makeImplPtr(output_stream);
61  }
62 
63 
64  void Writer::startMap(const Parameters &, const std::size_t num_entries)
65  {
66  impl_->packer_->pack_array(num_entries);
67  }
68 
69 
71  {
72  impl_->output_stream_->flush();
73  }
74 
75 
76  void Writer::startArray(const std::size_t size, const bool /*compact*/)
77  {
78  CPPUT_ASSERT(size <= std::numeric_limits<uint32_t>::max(), "Vector is too long.");
79  impl_->packer_->pack_array(size);
80  }
81 
82 
83 #define ARILES2_BASIC_TYPE(type) \
84  void Writer::writeElement(const type &element, const Parameters &) \
85  { \
86  impl_->packer_->pack(element); \
87  }
88 
90 
91 #undef ARILES2_BASIC_TYPE
92  } // namespace ns_msgpack_compact
93 } // namespace ariles2
void startArray(const std::size_t size, const bool=false)
void startMap(const Parameters &, const std::size_t num_entries)
Starts a nested map in the configuration file.
void flush()
Flush the configuration to the output.
Writer(const std::string &file_name)
Constructor.
std::shared_ptr<::msgpack::packer< std::ostream > > PackerPtr
void operator=(const Writer &)=delete
FileVisitorImplementation(const std::string &file_name)
Definition: write.h:384
#define CPPUT_ASSERT(condition,...)
Definition: exception.h:32
#define ARILES2_BASIC_TYPES_LIST
Definition: helpers.h:72
#define CPPUT_MACRO_SUBSTITUTE(macro)
Definition: misc.h:21
Definition: basic.h:17