00001
00020 #ifndef RTC_TYPENAME_H
00021 #define RTC_TYPENAME_H
00022
00023 #include <iostream>
00024 #include <rtm/RTC.h>
00025
00026 namespace CORBA_Util
00027 {
00034 template <class T, typename T::_ptr_type (*)(void)>
00035 struct has_nil_helper
00036 {
00037 typedef void type;
00038 };
00039
00043 template <class T, class U = void>
00044 struct has_nil_impl
00045 {
00046 static const bool value = false;
00047 };
00048
00055 template <class T>
00056 struct has_nil_impl<T, typename has_nil_helper<T, &T::_nil>::type>
00057 {
00058 static const bool value = true;
00059 };
00060
00068 template <class T>
00069 struct has_nil : has_nil_impl<T>
00070 {
00071 };
00072
00080 template <typename T>
00081 struct is_corba_object
00082 {
00083 static const bool value = has_nil<T>::value;
00084 };
00085
00093 template <bool cond, class T>
00094 class typecode;
00095
00096 template <class T>
00097 class typecode<true, T>
00098 {
00099 public:
00100 static const char* id()
00101 {
00102 CORBA::Any any_var;
00103 typename T::_ptr_type tmp_var;
00104 tmp_var = T::_nil();
00105 any_var <<= tmp_var;
00106 return any_var.type()->id();
00107 }
00108 static const char* name()
00109 {
00110 CORBA::Any any_var;
00111 typename T::_ptr_type tmp_var;
00112 tmp_var = T::_nil();
00113 any_var <<= tmp_var;
00114 return any_var.type()->name();
00115 }
00116 };
00117
00118 template <class T>
00119 class typecode<false, T>
00120 {
00121 public:
00122 static const char* id()
00123 {
00124 CORBA::Any any_var;
00125 T tmp_var;
00126 any_var <<= tmp_var;
00127 return any_var.type()->id();
00128 }
00129 static const char* name()
00130 {
00131 CORBA::Any any_var;
00132 T tmp_var;
00133 any_var <<= tmp_var;
00134 return any_var.type()->name();
00135 }
00136 };
00137
00138
00176 template <class T>
00177 const char* toTypename()
00178 {
00179 return typecode<is_corba_object<T>::value, T>::name();
00180 }
00181
00182 template <class T>
00183 const char* toTypenameOfStruct()
00184 {
00185 return typecode<false, T>::name();
00186 }
00187
00188 template <class T>
00189 const char* toTypenameOfObject()
00190 {
00191 return typecode<true, T>::name();
00192 }
00193
00231 template <class T>
00232 const char* toRepositoryId()
00233 {
00234 return typecode<is_corba_object<T>::value, T>::id();
00235 }
00236
00237 template <class T>
00238 const char* toRepositoryIdOfStruct()
00239 {
00240 return typecode<false, T>::id();
00241 }
00242
00243 template <class T>
00244 const char* toRepositoryIdOfObject()
00245 {
00246 return typecode<true, T>::id();
00247 }
00248
00249 };
00250
00251 template <class T>
00252 const char* toTypename()
00253 {
00254 std::cerr << "toTypename() is obsolete." << std::endl;
00255 std::cerr << "Please use CORBA_Util::toTypename() instead." << std::endl;
00256 return CORBA_Util::typecode<CORBA_Util::is_corba_object<T>::value, T>::name();
00257 }
00258
00259 #endif // RTC_TYPENAME_H