CUBRID Engine  latest
pinning.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * pinning.hpp
21  */
22 
23 #ifndef _PINNING_HPP_
24 #define _PINNING_HPP_
25 
26 #ident "$Id$"
27 
28 #include <set>
29 #include <assert.h>
30 #include <cstddef>
31 #include "error_code.h"
32 
33 namespace cubbase
34 {
35  class pinnable;
36 
37  class pinner
38  {
39  public:
40  int pin (pinnable *reference);
41  int unpin (pinnable *reference);
42 
43  int unpin_all (void);
44 
45  bool check_references (void)
46  {
47  return (references.size () == 0);
48  };
49 
51  {
52  assert (check_references () == true);
53  };
54 
55  private:
56  std::set <pinnable *> references;
57  };
58 
59  class pinnable
60  {
61  public:
62  int add_pinner (pinner *referencer)
63  {
64  pinners.insert (referencer);
65  return NO_ERROR;
66  }
67 
68  int remove_pinner (pinner *referencer)
69  {
70  pinners.erase (referencer);
71  return NO_ERROR;
72  }
73 
74  int get_pin_count (void)
75  {
76  return (int) pinners.size ();
77  }
78 
80  {
81  assert (pinners.size () == 0);
82  }
83 
84  private:
85  std::set <pinner *> pinners;
86  };
87 
88 } /* namespace cubbase */
89 
90 #endif /* _PINNING_HPP_ */
#define NO_ERROR
Definition: error_code.h:46
std::set< pinner * > pinners
Definition: pinning.hpp:85
int pin(pinnable *reference)
Definition: pinning.cpp:29
int add_pinner(pinner *referencer)
Definition: pinning.hpp:62
int get_pin_count(void)
Definition: pinning.hpp:74
#define assert(x)
std::set< pinnable * > references
Definition: pinning.hpp:53
int remove_pinner(pinner *referencer)
Definition: pinning.hpp:68
int unpin(pinnable *reference)
Definition: pinning.cpp:41
int unpin_all(void)
Definition: pinning.cpp:52
bool check_references(void)
Definition: pinning.hpp:45