StateFS
 All Classes Files Functions Variables Typedefs Enumerations Groups Pages
inout.hpp
1 #ifndef _STATEFS_MIRROR_HPP_
2 #define _STATEFS_MIRROR_HPP_
3 
4 /*
5  * Namespaces with mirrored property: data written to one property
6  * appears as content of the property with the same name on the other
7  * end
8  *
9  * Copyright (C) 2013 Jolla Ltd.
10  * Contact: Denis Zalevskiy <denis.zalevskiy@jollamobile.com>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16 
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21 
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25  * 02110-1301 USA
26  *
27  * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
28  */
29 
30 #include <statefs/provider.hpp>
31 #include <statefs/property.hpp>
32 #include <mutex>
33 
34 //using statefs::BranchStorage;
35 
36 namespace statefs { namespace inout {
37 
38 class Src;
39 
40 class Dst : public statefs::Namespace
41 {
42 public:
43  Dst(std::string const &);
44  virtual ~Dst();
45  virtual void release() {}
46 };
47 
48 class Src : public statefs::Namespace
49 {
51 public:
52  Src(std::string const &, std::shared_ptr<Dst>);
53  virtual ~Src();
54 
55  virtual void release() {}
56 
57  template <typename T>
58  void insert_inout(PropTraits<T> const &t)
59  {
60  auto out = t.create();
61  *dst_ << out;
62  insert_input(t.name, setter(out));
63  }
64 
65 private:
66 
67  void insert_input(std::string const&, setter_type const&);
68 
69  std::shared_ptr<Dst> dst_;
70 };
71 
72 template <typename T>
73 Src& operator << (Src &ns, PropTraits<T> const &p)
74 {
75  ns.insert_inout(p);
76  return ns;
77 }
78 
79 }}
80 
81 #endif // _STATEFS_PROVIDER_HPP_