Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Object.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 2000 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // file : include/CGAL/Object.h
37 // package : Kernel_basic (3.14)
38 // source : Object.lw
39 // revision : 3.0
40 // revision_date : 02 Feb 2000
41 // author(s) : Stefan.Schirra
42 // Andreas Fabri
43 // Geert-Jan Giezeman
44 // Michael Seel
45 //
46 // coordinator : MPI Saarbruecken, Germany
47 //
48 // email : contact@cgal.org
49 // www : http://www.cgal.org
50 //
51 // ======================================================================
52 
53 #ifndef CGAL_OBJECT_H
54 #define CGAL_OBJECT_H
55 
56 #ifdef CGAL_CFG_NO_DYNAMIC_CAST
57 #error fatal error: dynamic cast not supported
58 #endif // CGAL_CFG_NO_DYNAMIC_CAST
59 
60 #include <CGAL/Handle_for.h>
61 
62 namespace CGAL {
63 
64 class Object;
65 class Object_base;
66 template <class T> class Wrapper;
67 
68 
69 class Object_base : public Ref_counted
70 {
71  public:
72  virtual ~Object_base() {}
73 };
74 
75 
76 template <class T>
77 class Wrapper : public Object_base
78 {
79  public:
80  Wrapper(const T& object) : _object(object) {}
81 
82  Wrapper() {}
83 
84  operator T() { return _object; }
85 
86  virtual ~Wrapper() {}
87 
88  private:
90 };
91 
92 
93 class Object
94 {
95  public:
96  Object() : ptr( static_cast<Object_base*>(0) ) {}
97 
99  {
100  ptr = base;
101  CGAL_kernel_assertion( !ptr || (ptr->count == 1));
102  }
103 
104  Object(const Object& o) : ptr(o.ptr)
105  { if (ptr) ptr->count++; }
106 
108  { if (ptr && (--ptr->count == 0)) { delete ptr; } }
109 
110  Object&
111  operator=(const Object& o)
112  {
113  if (o.ptr) o.ptr->count++;
114  if (ptr && (--ptr->count == 0)) { delete ptr; }
115  ptr = o.ptr;
116  return *this;
117  }
118 
119  bool
120  is_empty() const { return ptr == static_cast<Object_base*>(0); }
121 
122  template <class T>
123  friend bool assign(T& t, const Object& o);
124 
125  protected:
127 };
128 
129 
130 template <class T>
131 Object
132 make_object(const T& t)
133 { return Object(new Wrapper< T >(t)); }
134 
135 
136 template <class T>
137 bool
138 assign(T& t, const Object& o)
139 {
140 # ifdef CGAL_CFG_DYNAMIC_CAST_BUG
141  Wrapper<T> instantiate_it;
142 # endif // CGAL_CFG_DYNAMIC_CAST_BUG
143  Wrapper<T>* wp = dynamic_cast<Wrapper<T>*>(o.ptr);
144  if ( wp == static_cast<Wrapper<T>*>(0) ) { return false; }
145  t = *(wp);
146  return true;
147 }
148 
149 } // namespace CGAL
150 
151 #endif // CGAL_OBJECT_H
152 
Object make_object(const T &t)
Definition: Object.h:132
Object & operator=(const Object &o)
Definition: Object.h:111
unsigned int count
Definition: Handle_for.h:76
Object(const Object &o)
Definition: Object.h:104
bool is_empty() const
Definition: Object.h:120
virtual ~Object_base()
Definition: Object.h:72
bool assign(T &t, const Object &o)
Definition: Object.h:138
Wrapper(const T &object)
Definition: Object.h:80
friend bool assign(T &t, const Object &o)
Definition: Object.h:138
virtual ~Wrapper()
Definition: Object.h:86
Object_base * ptr
Definition: Object.h:126
Object(Object_base *base)
Definition: Object.h:98
#define CGAL_kernel_assertion(EX)