Vowpal Wabbit
options_serializer_boost_po.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "options.h"
4 
5 #include "options_types.h"
6 
7 #include "vw_exception.h"
8 
9 #include <sstream>
10 
11 namespace VW
12 {
13 namespace config
14 {
16 {
18 
19  virtual void add(base_option& option) override;
20  virtual std::string str() override;
21  virtual const char* data() override;
22  virtual size_t size() override;
23 
24  private:
25  template <typename T>
27  {
28  if (base_option.m_type_hash == typeid(T).hash_code())
29  {
30  auto typed = dynamic_cast<typed_option<T>&>(base_option);
31  serialize(typed);
32  return true;
33  }
34 
35  return false;
36  }
37 
38  template <typename T>
40  {
41  m_output_stream << " --" << typed_option.m_name << " " << typed_option.value();
42  }
43 
44  template <typename T>
45  void serialize(typed_option<std::vector<T>>& typed_option)
46  {
47  auto vec = typed_option.value();
48  if (vec.size() > 0)
49  {
50  for (auto const& value : vec)
51  {
53  m_output_stream << " " << value;
54  }
55  }
56  }
57 
58  template <typename TTypes>
59  void add_impl(base_option& options)
60  {
61  if (serialize_if_t<typename TTypes::head>(options))
62  {
63  return;
64  }
65  add_impl<typename TTypes::tail>(options);
66  }
67 
68  std::stringstream m_output_stream;
69 };
70 
71 template <>
72 void options_serializer_boost_po::serialize<bool>(typed_option<bool>& typed_argument);
73 
74 template <>
75 void options_serializer_boost_po::add_impl<typelist<>>(base_option& options);
76 } // namespace config
77 } // namespace VW
void serialize(typed_option< T > &typed_option)
void serialize(typed_option< std::vector< T >> &typed_option)
std::string m_name
Definition: options.h:17
typed_option & value(T value)
Definition: options.h:63
virtual void add(base_option &option) override
Definition: autolink.cc:11