00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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>
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
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:
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:
00067 case tk_wchar:
00068 case tk_boolean:
00069 case tk_float:
00070 case tk_double:
00071 #ifdef HAS_LongDouble
00072 case tk_longdouble:
00073 #endif
00074 case tk_string:
00075 case tk_wstring:
00076 case tk_fixed:
00077 case tk_octet:
00078 {
00079 TypeCode_var valueTc=_value.type();
00080 _type_def.assign(IDLType::_duplicate(v));
00081
00082 if(!vTc->equivalent(valueTc))
00083 _value=Any();
00084 }
00085 break;
00086
00087 default:
00088 throw CORBA::BAD_PARAM();
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(
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();
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));
00153 _value>>=memstr;
00154 PersistNode::outputCdrMemoryStream(os,memstr,"\n value=");
00155 os<<" ;;\n";
00156 }
00157
00158 }