SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Datatype.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file Datatype.h
33 ///@brief The Datatype Data type
34 ///
35 ///@author
36 /// David Weinstein
37 /// Department of Computer Science
38 /// University of Utah
39 ///@date July 1994
40 ///
41 ///
42 
43 #ifndef CORE_DATATYPES_DATATYPE_H
44 #define CORE_DATATYPES_DATATYPE_H 1
45 
46 #include <boost/type_traits.hpp>
48 #include <Core/Thread/UsedWithLockingHandle.h>
49 #include <Core/Containers/LockingHandle.h>
50 #include <Core/Thread/RecursiveMutex.h>
51 
52 #include <Core/Datatypes/share.h>
53 
54 namespace SCIRun {
55 
56 class SCISHARE Datatype : public Persistent, public UsedWithLockingHandle<RecursiveMutex>
57 {
58 public:
59  /// unique id for each instance
61  Datatype();
62  Datatype(const Datatype&);
63  Datatype& operator=(const Datatype&);
64  virtual ~Datatype();
65 
66  virtual std::string dynamic_type_name() const = 0;
67 
68  static int compute_new_generation();
69 };
70 
71 typedef LockingHandle<Datatype> DatatypeHandle;
72 
73 #ifdef APPLE_LEOPARD_OR_SNOW_LEOPARD
74 
75 #define SCI_DATATYPE_CAST sci_datatype_cast
76 
77 #else
78 
79 #define SCI_DATATYPE_CAST dynamic_cast
80 
81 #endif
82 
83 template <typename TPtr>
85 {
86  if (! handle)
87  return 0;
88 
89  const std::string realType = handle->dynamic_type_name();
90 
91  typedef typename boost::remove_pointer<TPtr>::type return_type;
92  const std::string returnType = return_type::type_id.type;
93 
94  if (Persistent::is_base_of(returnType, realType))
95  return static_cast<TPtr>(handle);
96 
97  return 0;
98 }
99 
100 } // End namespace SCIRun
101 
102 
103 #endif /* SCI_project_Datatype_h */
Definition: Persistent.h:187
#define SCISHARE
Definition: share.h:39
TPtr sci_datatype_cast(Datatype *handle)
Definition: Datatype.h:84
Base class for persistent objects...
Definition: Datatype.h:56
LockingHandle< Datatype > DatatypeHandle
Definition: Datatype.h:71
static bool is_base_of(const std::string &parent, const std::string &type)
Definition: Persistent.cc:761
int generation
unique id for each instance
Definition: Datatype.h:60
virtual std::string dynamic_type_name() const =0
Definition: UsedWithLockingHandle.h:44