00001 #ifndef ACSUTIL_ANY_AIDE_H 00002 #define ACSUTIL_ANY_AIDE_H 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) Associated Universities Inc., 2003 00006 * 00007 *This library is free software; you can redistribute it and/or 00008 *modify it under the terms of the GNU Lesser General Public 00009 *License as published by the Free Software Foundation; either 00010 *version 2.1 of the License, or (at your option) any later version. 00011 * 00012 *This library is distributed in the hope that it will be useful, 00013 *but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 *Lesser General Public License for more details. 00016 * 00017 *You should have received a copy of the GNU Lesser General Public 00018 *License along with this library; if not, write to the Free Software 00019 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * "@(#) $Id: acsutilAnyAide.h,v 1.11 2008/10/09 02:23:13 cparedes Exp $" 00022 * 00023 * who when what 00024 * -------- -------- ---------------------------------------------- 00025 * dfugate 2005-08-11 created 00026 */ 00028 #ifndef __cplusplus 00029 #error This is a C++ include file and cannot be used from plain C 00030 #endif 00031 00032 00036 #include <sstream> 00037 #include <tao/AnyTypeCode/Any.h> 00038 #include <tao/AnyTypeCode/TypeCode.h> 00039 00045 class AnyAide 00046 { 00047 public: 00048 00055 struct WrongTemplateParameter 00056 { 00057 std::string correctParameter; 00058 }; 00059 00065 struct UnsupportedType 00066 { 00067 std::string type; 00068 }; 00069 00070 00077 static CORBA::TCKind 00078 getRealType(const CORBA::Any&); 00079 00095 static std::string 00096 getId(const CORBA::Any&); 00097 00109 static std::string 00110 anyToString(const CORBA::Any&, unsigned short precision=0); 00111 00124 template <class T> 00125 static T 00126 getValue(const CORBA::Any& any) 00127 { 00128 T returnVal; 00129 //standard CORBA way of extracting an any 00130 if((any >>= returnVal)==false) 00131 { 00132 //it failed because it's the wrong type 00133 //just throw an exception. 00134 WrongTemplateParameter except; 00135 except.correctParameter = getId(any); 00136 throw except; 00137 } 00138 return returnVal; 00139 } 00140 00148 template <class T> 00149 static void 00150 setValue(CORBA::Any& any, 00151 const T& value) 00152 { 00153 any <<= value; 00154 } 00155 00156 00157 //------------------------------------------------ 00158 //set of functions below designed to tell developers 00159 //if the any is of a given type. 00160 00164 static bool 00165 isNull(const CORBA::Any&); 00166 00170 static bool 00171 isString(const CORBA::Any&); 00172 00176 static bool 00177 isDouble(const CORBA::Any&); 00178 00182 static bool 00183 isFloat(const CORBA::Any&); 00184 00188 static bool 00189 isLong(const CORBA::Any&); 00190 00194 static bool 00195 isLongLong(const CORBA::Any&); 00196 00200 static bool 00201 isULongLong(const CORBA::Any&); 00202 00206 static bool 00207 isULong(const CORBA::Any&); 00208 00212 static bool 00213 isPattern(const CORBA::Any&); 00214 00218 static bool 00219 isDoubleSeq(const CORBA::Any&); 00220 00224 static bool 00225 isLongSeq(const CORBA::Any&); 00226 00230 static bool 00231 isStringSeq(const CORBA::Any&); 00232 00236 static bool 00237 isFloatSeq(const CORBA::Any&); 00238 00242 static bool 00243 isEnum(const CORBA::Any&); 00244 00248 static bool 00249 isStruct(const CORBA::Any&); 00250 00251 //------------------------------------------------------ 00252 //--members below define the ID returned by the getId 00253 //--method for SIMPLE TYPES ONLY! this is done because 00254 //--there is no way to get the IFR ID of these types 00255 //--from the CORBA any. with complex types like enumerations, 00256 //--structs, etc we do not have to declare these here 00257 //--because this info can be obtained dynamically 00258 00260 static const std::string nullType_m; 00261 00263 static const std::string stringType_m; 00264 00266 static const std::string doubleType_m; 00267 00269 static const std::string floatType_m; 00270 00272 static const std::string longType_m; 00273 00275 static const std::string longLongType_m; 00276 00278 static const std::string uLongLongType_m; 00279 00281 static const std::string uLongType_m; 00282 00284 static const std::string patternType_m; 00285 00287 static const std::string doubleSeqType_m; 00288 00290 static const std::string longSeqType_m; 00291 00293 static const std::string stringSeqType_m; 00294 00296 static const std::string floatSeqType_m; 00297 00304 static const std::string unknownType_m; 00305 00306 00307 private: 00313 static std::string 00314 enumToString(const CORBA::Any&); 00315 00316 }; 00317 00318 #endif