jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
datum.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_FV_CONVERTER_DATUM_HPP_
18 #define JUBATUS_CORE_FV_CONVERTER_DATUM_HPP_
19 
20 #include <map>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 #include <msgpack.hpp>
25 #include "jubatus/util/data/serialization.h"
26 
27 namespace jubatus {
28 namespace core {
29 namespace fv_converter {
30 
31 struct datum {
32  typedef std::vector<std::pair<std::string, std::string> > sv_t;
33  typedef std::vector<std::pair<std::string, double> > nv_t;
34 
38 
39  MSGPACK_DEFINE(string_values_, num_values_, binary_values_);
40 
41  template<class Archiver>
42  void serialize(Archiver& ar) {
43  std::map<std::string, std::string> sv;
44  std::map<std::string, double> nv;
45  std::map<std::string, std::string> bv;
46  if (ar.is_read) {
47  ar
48  & JUBA_NAMED_MEMBER("string_values", sv)
49  & JUBA_NAMED_MEMBER("num_values", nv)
50  & JUBA_NAMED_MEMBER("binary_values", bv);
51  string_values_ = sv_t(sv.begin(), sv.end());
52  num_values_ = nv_t(nv.begin(), nv.end());
53  binary_values_ = sv_t(bv.begin(), bv.end());
54  } else {
55  sv.insert(string_values_.begin(), string_values_.end());
56  nv.insert(num_values_.begin(), num_values_.end());
57  bv.insert(binary_values_.begin(), binary_values_.end());
58  ar
59  & JUBA_NAMED_MEMBER("string_values", sv)
60  & JUBA_NAMED_MEMBER("num_values", nv)
61  & JUBA_NAMED_MEMBER("binary_values", bv);
62  }
63  }
64 };
65 
66 } // namespace fv_converter
67 } // namespace core
68 } // namespace jubatus
69 
70 #endif // JUBATUS_CORE_FV_CONVERTER_DATUM_HPP_
void serialize(Archiver &ar)
Definition: datum.hpp:42
MSGPACK_DEFINE(string_values_, num_values_, binary_values_)
std::vector< std::pair< std::string, std::string > > sv_t
Definition: datum.hpp:32
std::vector< std::pair< std::string, double > > nv_t
Definition: datum.hpp:33