libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attachable.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ATTACHABLE_HPP_
19 #define FOEDUS_ATTACHABLE_HPP_
20 
21 #include "foedus/cxx11.hpp"
22 #include "foedus/fwd.hpp"
23 namespace foedus {
57 template <typename CONTROL_BLOCK>
58 class Attachable {
59  public:
61  explicit Attachable(Engine* engine) : engine_(engine), control_block_(CXX11_NULLPTR) {}
62  Attachable(Engine* engine, CONTROL_BLOCK* control_block)
64  attach(control_block);
65  }
66  explicit Attachable(CONTROL_BLOCK* control_block)
68  attach(control_block);
69  }
70  virtual ~Attachable() {}
71 
72  // copy constructors
73  Attachable(const Attachable& other)
74  : engine_(other.engine_), control_block_(other.control_block_) {}
75  Attachable& operator=(const Attachable& other) {
76  engine_ = other.engine_;
78  return *this;
79  }
80 
91  virtual void attach(CONTROL_BLOCK* control_block) {
92  control_block_ = control_block;
93  }
94 
96  bool is_attached() const { return control_block_; }
97  CONTROL_BLOCK* get_control_block() const { return control_block_; }
98 
99  Engine* get_engine() const { return engine_; }
100  void set_engine(Engine* engine) { engine_ = engine; }
101 
102  protected:
111  CONTROL_BLOCK* control_block_;
112 };
113 
114 
115 } // namespace foedus
116 #endif // FOEDUS_ATTACHABLE_HPP_
void set_engine(Engine *engine)
Definition: attachable.hpp:100
Attachable(const Attachable &other)
Definition: attachable.hpp:73
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Attachable & operator=(const Attachable &other)
Definition: attachable.hpp:75
virtual ~Attachable()
Definition: attachable.hpp:70
Forward declarations of classes in root package.
virtual void attach(CONTROL_BLOCK *control_block)
Attaches to the given shared memory.
Definition: attachable.hpp:91
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
Attachable(Engine *engine)
Definition: attachable.hpp:61
bool is_attached() const
Returns whether the object has been already attached to some shared memory.
Definition: attachable.hpp:96
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Engine * get_engine() const
Definition: attachable.hpp:99
Attachable(CONTROL_BLOCK *control_block)
Definition: attachable.hpp:66
Attachable Resources on Shared Memory.
Definition: attachable.hpp:58
Attachable(Engine *engine, CONTROL_BLOCK *control_block)
Definition: attachable.hpp:62
CONTROL_BLOCK * get_control_block() const
Definition: attachable.hpp:97