Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / DF / DF_definitions.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef  DF_DEF_HXX
23 #define  DF_DEF_HXX
24
25 #ifdef WIN32
26 # ifdef DF_EXPORTS
27 #  define DF_EXPORT __declspec( dllexport )
28 # else
29 #  define DF_EXPORT __declspec( dllimport )
30 # endif
31 #else
32 # define DF_EXPORT
33 #endif
34
35 #include <iostream> 
36 #include <stdio.h>
37 #include <boost/shared_ptr.hpp> 
38
39 template<class T> class df_shared_ptr: public boost::shared_ptr<T>
40 {
41 public:
42   df_shared_ptr() {}
43   
44   template<class Y>
45     explicit df_shared_ptr(Y * p)
46       {
47         boost::shared_ptr<T>::reset(p);
48       }
49   
50   template<class Y>
51     df_shared_ptr(df_shared_ptr<Y> const & r):
52       boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag())
53         {}
54   
55   template<class Y>
56     df_shared_ptr & operator=(df_shared_ptr<Y> const & r)
57       {
58         df_shared_ptr<T>(r).swap(*this);
59         return *this;
60       }
61   
62   template<class Y> df_shared_ptr& operator()(Y * p) // Y must be complete
63     {
64       if(T* pt = dynamic_cast<T*>(p))
65         boost::shared_ptr<T>::reset(pt);
66       else
67         boost::throw_exception(std::bad_cast());
68       return *this;
69     }
70     
71 };
72
73 # if defined(WIN32) && !defined(HAVE_NO_DLL)
74
75 #  ifndef Standard_EXPORT
76 #   define Standard_EXPORT __declspec( dllexport )
77 // For global variables :
78 #   define Standard_EXPORTEXTERN __declspec( dllexport ) extern
79 #   define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport )
80 #  endif  /* Standard_EXPORT */
81
82 #  ifndef Standard_IMPORT
83 #   define Standard_IMPORT __declspec( dllimport ) extern
84 #   define Standard_IMPORTC extern "C" __declspec( dllimport )
85 #  endif  /* Standard_IMPORT */
86
87 # else  /* WIN32 */
88
89 #  ifndef Standard_EXPORT
90 #   define Standard_EXPORT
91 // For global variables :
92 #   define Standard_EXPORTEXTERN extern
93 #   define Standard_EXPORTEXTERNC extern "C"
94 #  endif  /* Standard_EXPORT */
95
96 #  ifndef Standard_IMPORT
97 #   define Standard_IMPORT extern
98 #   define Standard_IMPORTC extern "C"
99 #  endif  /* Standard_IMPORT */
100
101 # endif  /* WIN32 */
102
103 # ifndef __Standard_API
104 //#  ifdef WIN32
105 #   if !defined(WIN32) 
106 #    define __Standard_API Standard_EXPORT
107 #    define __Standard_APIEXTERN Standard_EXPORTEXTERN
108 #   else
109 #    define __Standard_API Standard_IMPORT
110 #    define __Standard_APIEXTERN Standard_IMPORT
111 #   endif  // __Standard_DLL
112 //#  else
113 //#   define __Standard_API
114 //#  endif  // WIN32
115 # endif  // __Standard_API
116
117 #include <iostream>
118 class Standard_EXPORT DFexception
119 {
120 public :
121   DFexception(const char *message) {
122     std::cerr << message << std::endl;
123   }
124 }; 
125
126
127 #endif