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

StructDef.cc

Go to the documentation of this file.
00001 //                            Package   : omniIFR
00002 //  StructDef.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 "StructDef.h"
00024 
00025 #include "Repository.h"
00026 #include "PersistNode.h"
00027 
00028 namespace Omniifr {
00029 
00030 StructMemberSeq* StructDef_impl::members()
00031 {
00032   return _members.copy();
00033 }
00034 
00035 void StructDef_impl::members(const StructMemberSeq& v)
00036 {
00037   checkReadonly();
00038   // Spec: "When setting the members attribute, the type member of the
00039   // StructMember structure should be set to TC_void."
00040   // I interpret this as meaning that the type member is set by the setter
00041   // method (here). The word 'should' implies a recommendation rather than an 
00042   // imperative - I choose to not throw an exception if type is set, only to
00043   // ignore its value.
00044   StructMemberSeq temp(v); // take a copy (v is const).
00045   for(ULong i=0; i<temp.length(); i++)
00046   {
00047     if(CORBA::is_nil(temp[i].type_def))
00048         throw CORBA::BAD_PARAM(
00049           IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidObjectRef,43),
00050           CORBA::COMPLETED_NO
00051         );
00052     try {
00053         temp[i].type=temp[i].type_def->type();
00054     }
00055     catch(...) {
00056       DB(15,"Caught exception at "<<__FILE__<<":"<<__LINE__)
00057       throw; // If an exception occurs, just propagate it as-is.
00058     }
00059   }
00060 
00061   _members.assign(temp);
00062 }
00063 
00064 TypeCode_ptr StructDef_impl::type()
00065 {
00066   return Repository_impl::inst()._orb
00067          ->create_struct_tc(_id.in(),_name.in(),_members.in());
00068 }
00069 
00070 void StructDef_impl::uncheckedDestroy()
00071 {
00072   _members.clear();
00073   Contained_impl::uncheckedDestroy();
00074   Container_impl::uncheckedDestroy();
00075 }
00076 
00077 bool StructDef_impl::canContain(DefinitionKind kind)
00078 {
00079   switch(kind)
00080   {
00081     case dk_Struct:
00082     case dk_Union:
00083     case dk_Enum:
00084       return true;
00085     default:
00086       return false;
00087   }
00088 }
00089 
00090 void StructDef_impl::reincarnate(const PersistNode& node)
00091 {
00092   cdrMemoryStream memstr =node.attrCdrStream("state");
00093   StructMemberSeq m;
00094   m<<=memstr;
00095   _members.uncheckedAssign(m); // Skip the checks performed by members(m)
00096 }
00097 
00098 void StructDef_impl::output(ostream &os)
00099 {
00100   outputSelf(os,"StructDef");
00101   cdrMemoryStream memstr(CORBA::ULong(0),CORBA::Boolean(1)/*clearMemory*/);
00102   _members.in()>>=memstr;
00103   PersistNode::outputCdrMemoryStream(os,memstr,"\n state=");
00104   os<<" ;;\n";
00105   outputContents(os);
00106 }
00107 
00108 } // end namespace Omniifr

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