MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; version 2 of the
7  * License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #ifndef _MFORMS_BASE_H_
20 #define _MFORMS_BASE_H_
21 
22 #include <string>
23 #include <list>
24 #include "base/threading.h"
25 
26 #ifdef _WIN32
27 # ifdef DECL_MFORMS_EXPORT
28 # define MFORMS_EXPORT __declspec(dllexport)
29 # else
30 # define MFORMS_EXPORT __declspec(dllimport)
31 # endif
32 #else
33 # define MFORMS_EXPORT
34 #endif
35 
36 #if defined(__APPLE__) && !defined(MFORMS_STUB)
37 #ifdef nil
38 #undef nil
39 #endif
40 #define nil __DARWIN_NULL
41 #include <objc/objc-runtime.h>
42 #endif
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 namespace mforms {
46 
47  // The root of of mforms hierarchy.
48  class MFORMS_EXPORT Object
49  {
50  public:
51  Object *retain();
52  void release();
53  virtual void set_managed();
54  void set_release_on_add();
55  bool is_managed();
56  bool release_on_add();
57 
58 // Below code is used only for debug purpose.
59 #ifdef _0
60  int retain_count();
61 #endif
62 
63  void set_destroying();
64  bool is_destroying();
65 
66 #ifndef SWIG
67 #if defined(__APPLE__) && !defined(MFORMS_STUB)
70  public:
71  Object();
72  virtual ~Object();
73 
74  void set_data(id data);
75  id get_data() const;
76 
77  private:
78  id _data;
79 #else // !__APPLE__
80  public:
81  Object();
82  virtual ~Object();
83 
84  typedef void (*FreeDataFn)(void*);
85  void set_data(void *data, FreeDataFn free_fn = 0);
86 
87  template<class C>
88  C* get_data() const { return reinterpret_cast<C*>(_data); }
89 
90  void *get_data_ptr() const;
91 
92  private:
93  void *_data;
94  FreeDataFn _data_free_fn;
95 #endif // !__APPLE__
96  volatile mutable base::refcount_t _refcount;
97  //We use only ptr's in mforms.
98  Object(Object const& o) { throw std::logic_error("Copy c-tor unsupported in mforms::Object"); }
99  Object& operator= (Object const& o) { throw std::logic_error("Assignment operator not supported in mforms::Object"); return *this; }
100  protected:
101  bool _managed;
102  bool _release_on_add;
103 #endif // !SWIG
104  private:
105  bool _destroying;
106  };
107 
108 
110  // Must be called for objects allocated with new that you won't delete manually
111  template<class C>
112  C* manage(C *obj, bool release_on_add = true)
113  {
114  obj->set_managed();
115  if (release_on_add)
116  obj->set_release_on_add();
117  return obj;
118  }
119 };
120 
121 #endif // !DOXYGEN_SHOULD_SKIP_THIS
122 #endif
#define MFORMS_EXPORT
Definition: base.h:33
MySQL Workbench 6.1 documentation