Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ConstantDef.cc

Go to the documentation of this file.
00001 //                            Package   : omniIFR
00002 //  ConstantDef.cc            Created   : 2004/02/22
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2004 Alex Tingle.
00006 //
00007 //    This file is part of the omniIFR application.
00008 //
00009 //    omniIFR is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniIFR is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 #include "ConstantDef.h"
00024 
00025 #include "idltype.h"
00026 #include "Container.h"
00027 #include "PersistNode.h"
00028 #include "string_to.h"
00029 
00030 #include <stdio.h> // sprintf
00031 
00032 namespace Omniifr {
00033 
00034 TypeCode_ptr ConstantDef_impl::type()
00035 {
00036   return _type_def.in()->type();
00037 }
00038 
00039 IDLType_ptr ConstantDef_impl::type_def()
00040 {
00041   return IDLType::_duplicate(_type_def.in());
00042 }
00043 
00044 void ConstantDef_impl::type_def(IDLType_ptr v)
00045 {
00046   checkReadonly();
00047   TypeCode_var vTc  =v->type();
00048   TCKind       kind =vTc->kind();
00049   // Strip out aliases. <scoped_name>
00050   while(kind==tk_alias)
00051   {
00052     vTc=vTc->content_type();
00053     kind=vTc->kind();
00054   }
00055 
00056   switch(kind)
00057   {
00058     case tk_short:   // <integer_type>
00059     case tk_ushort: 
00060     case tk_long: 
00061     case tk_ulong: 
00062 #ifdef HAS_LongLong
00063     case tk_longlong: 
00064     case tk_ulonglong: 
00065 #endif
00066     case tk_char:    // <char_type>
00067     case tk_wchar:   // <wide_char_type>
00068     case tk_boolean: // <boolean_type>
00069     case tk_float:   // <floating_pt_type>
00070     case tk_double: 
00071 #ifdef HAS_LongDouble
00072     case tk_longdouble: 
00073 #endif
00074     case tk_string:  // <string_type>
00075     case tk_wstring: // <wide_string_type>
00076     case tk_fixed:   // <fixed_pt_const_type>
00077     case tk_octet:   // <octet_type>
00078       {
00079         TypeCode_var valueTc=_value.type();
00080         _type_def.assign(IDLType::_duplicate(v)); // May throw...
00081         // Erase _value here, unless its TypeCode matches 'v'.
00082         if(!vTc->equivalent(valueTc))
00083            _value=Any();
00084       }
00085       break;
00086 
00087     default:
00088       throw CORBA::BAD_PARAM(); // ?? Minor code
00089   }
00090 }
00091 
00092 CORBA::Any* ConstantDef_impl::value()
00093 {
00094   return new CORBA::Any(_value);
00095 }
00096 
00097 void ConstantDef_impl::value(const Any& v)
00098 {
00099   checkReadonly();
00100   CORBA::TypeCode_var thisTc =this->type();
00101   CORBA::TypeCode_var vTc    =v.type();
00102   if(thisTc->equivalent(vTc.in()))
00103   {
00104     _value=v;
00105   }
00106   else
00107   {
00108     throw CORBA::BAD_PARAM( // Mico throws NO_PERMISSION here.
00109       IFELSE_OMNIORB4(omni::BAD_PARAM_TargetIsInvalidContainer,4),
00110       CORBA::COMPLETED_NO
00111     );
00112   }
00113 }
00114 
00115 Contained::Description* ConstantDef_impl::describe()
00116 {
00117   ConstantDescription_var constantdesc =new ConstantDescription();
00118   constantdesc->name       =name();
00119   constantdesc->id         =id();
00120   constantdesc->version    =version();
00121   constantdesc->type       =type();
00122   constantdesc->value      =_value;
00123   constantdesc->defined_in =definedInId();
00124 
00125   CORBA::Contained::Description_var description =
00126     new CORBA::Contained::Description();
00127   description->kind  =   def_kind();
00128   description->value <<= constantdesc._retn();
00129 
00130   return description._retn();
00131 }
00132 
00133 void ConstantDef_impl::uncheckedDestroy()
00134 {
00135   _type_def.clear();
00136   Contained_impl::uncheckedDestroy(); // superclass
00137 }
00138 
00139 void ConstantDef_impl::reincarnate(const PersistNode& node)
00140 {
00141   _type_def.assign(
00142     string_to_<IDLType>(node.attrString("type_def").c_str())
00143   );
00144   cdrMemoryStream memstr =node.attrCdrStream("value");
00145   _value<<=memstr;
00146 }
00147 
00148 void ConstantDef_impl::output(ostream &os)
00149 {
00150   outputSelf(os,"ConstantDef");
00151   PersistNode::outputIOR(os,_type_def.in(),"\n type_def=");
00152   cdrMemoryStream memstr(CORBA::ULong(0),CORBA::Boolean(1)/*clearMemory*/);
00153   _value>>=memstr;
00154   PersistNode::outputCdrMemoryStream(os,memstr,"\n value=");
00155   os<<" ;;\n";
00156 }
00157 
00158 } // end namespace Omniifr

Generated on Fri Mar 4 13:03:22 2005 for OmniIFR by  doxygen 1.4.1