accessor.h
1 /*
2  @copyright Russell Standish 2013
3  @author Russell Standish
4  This file is part of EcoLab
5 
6  Open source licensed under the MIT license. See LICENSE for details.
7 */
8 
9 #ifndef ACCESSOR_H
10 #define ACCESSOR_H
11 #include "pack_base.h"
12 #if defined(__cplusplus) && __cplusplus>=201103L
13 #include <functional>
14 #endif
15 
16 namespace ecolab
17 {
18 #if defined(__cplusplus) && __cplusplus>=201103L
19  using std::function;
20 #else
21  template <class F>
22  struct function {};
23 #endif
24 
30  template <class T, class Getter=function<T()>,
31  class Setter=function<T(const T&)> >
32  struct Accessor
33  {
34  Getter g;
35  Setter s;
36  Accessor(const Getter& g, const Setter& s): g(g), s(s) {}
37  T operator()() const {return g();}
38  T operator()(const T& x) const {return s(x);}
39  // assignment and copying don't really make sense
40  void operator=(const Accessor&) {}
41  private:
42  // there is no way to give a meaningful copy constructor, as this
43  // object needs to contain a reference to the object it is
44  // acessing, which the source object knows nothing about.
45  Accessor(const Accessor&);
46  };
47 }
48 
49 #ifdef _CLASSDESC
50 #pragma omit pack ecolab::Accessor
51 #pragma omit unpack ecolab::Accessor
52 #pragma omit TCL_obj ecolab::Accessor
53 #endif
54 
56 {
57  namespace cd=classdesc;
58  template <class T, class G, class S>
59  struct access_pack<ecolab::Accessor<T,G,S> >:
60  public cd::NullDescriptor<cd::pack_t> {};
61  template <class T, class G, class S>
62  struct access_unpack<ecolab::Accessor<T,G,S> >:
63  public cd::NullDescriptor<cd::unpack_t> {};
64 }
65 
66 #endif
serialisation descriptor
Definition: accessor.h:22
class to allow access to private members
Definition: classdesc_access.h:21
helper for constructing null descriptors
Definition: classdesc.h:784
class to allow access to private members
Definition: classdesc_access.h:22
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
_OPENMP
Definition: accessor.h:16
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: accessor.h:32