Re: sequence implementation



Bowie Owens wrote:

I have been trying to put together a similar patch to implement sequence of sequences.

http://bugzilla.gnome.org/show_bug.cgi?id=108644

However, I am stuck because I am not sure what types I should be using for the member type/sequences. I have attached a patch which shows my current changes to the orbitcpp-1.3.5 source. Any direction on where to go from here would be appreciated.

I think I have it worked out now. Attached should be a patch that implements IDLSequence::get_seq_typename (and IDLEnum::get_seq_typename). The patch adds a new sequence traits class template seq_seq_traits which provides the traits required when a sequence is used as the element type of a sequence. I had to make CompoundSeqBase, CompoundBoundedSeq and CompoundUnboundedSeq take their SeqTraits from an additional template parameter (which defaults to CPPElem::SeqTraits to avoid breaking everything else).

This compiles and works for me on RedHat Linux 8.0 with GCC 3.2.

--
Bowie Owens

CSIRO Mathematical & Information Sciences
phone  : +61 3 9545 8055
fax    : +61 3 9545 8080
mobile : 0425 729 875
email  : Bowie Owens csiro au


diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLEnum.cc ./orbitcpp/idl-compiler/types/IDLEnum.cc
*** ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLEnum.cc	Thu Feb  6 07:48:28 2003
--- ./orbitcpp/idl-compiler/types/IDLEnum.cc	Wed Mar 26 11:04:07 2003
***************
*** 66,68 ****
--- 66,94 ----
  
  	return result;
  }
+ 
+ string
+ IDLEnum::get_seq_typename (unsigned int      length,
+ 			       const IDLTypedef *active_typedef) const
+ {
+ 	string retval;
+ 
+ 	char *tmp = 0;
+ 	char *traits = g_strdup_printf(IDL_IMPL_NS "::enum_seq_traits< %s, %s, CORBA_sequence_%s, TC_CORBA_sequence_%s>",
+ 				       get_cpp_member_typename ().c_str (),
+ 				       get_c_member_typename ().c_str (),
+ 				       get_c_member_typename ().c_str (),
+ 				       get_c_member_typename ().c_str ());
+ 	if (length)
+ 		tmp = g_strdup_printf (IDL_IMPL_NS "::SimpleBoundedSeq< %s, %d>",
+ 				       traits, length);
+ 	else
+ 		tmp = g_strdup_printf (IDL_IMPL_NS "::SimpleUnboundedSeq< %s >",
+ 				       traits);
+ 	
+ 	g_free (traits);
+ 	retval = tmp;
+ 	g_free (tmp);
+ 	
+ 	return retval;
+ }
diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLEnum.h ./orbitcpp/idl-compiler/types/IDLEnum.h
*** ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLEnum.h	Thu Feb  6 07:48:28 2003
--- ./orbitcpp/idl-compiler/types/IDLEnum.h	Tue Mar 25 10:32:57 2003
***************
*** 58,63 ****
--- 58,66 ----
  	std::string discr_get_cpp_typename () const {
  		return get_fixed_cpp_typename ();
  	}
+ 
+ 	std::string get_seq_typename (unsigned int      length,
+ 			       const IDLTypedef *active_typedef) const;
  };
  
  #endif //ORBITCPP_TYPES_IDLENUM
diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLSequence.cc ./orbitcpp/idl-compiler/types/IDLSequence.cc
*** ../orig/orbitcpp-1.3.5/orbitcpp/idl-compiler/types/IDLSequence.cc	Sun Mar 16 00:38:36 2003
--- ./orbitcpp/idl-compiler/types/IDLSequence.cc	Wed Mar 26 13:42:41 2003
***************
*** 407,413 ****
  IDLSequence::get_seq_typename (unsigned int      length,
  			       const IDLTypedef *active_typedef) const
  {
! #warning "WRITE ME"
  }
  	
  string
--- 407,437 ----
  IDLSequence::get_seq_typename (unsigned int      length,
  			       const IDLTypedef *active_typedef) const
  {
! 	string retval;
! 
! 	char *tmp = 0;
! 	std::string seq_typename = m_element_type.get_seq_typename (m_length);
! 	std::string c_member_typename_base = get_c_member_typename (active_typedef);
! 	std::string::size_type pos = c_member_typename_base.find('*');
! 	g_assert (pos != std::string::npos);
! 	c_member_typename_base.replace(pos, 1, "");
! 	char *traits = g_strdup_printf(IDL_IMPL_NS "::seq_seq_traits< %s, %s, CORBA_sequence_%s, TC_CORBA_sequence_%s>",
! 				       seq_typename.c_str () ,
! 				       c_member_typename_base.c_str (),
! 				       c_member_typename_base.c_str (),
! 				       c_member_typename_base.c_str ());
! 	if (length)
! 		tmp = g_strdup_printf (IDL_IMPL_NS "::CompoundBoundedSeq< %s, %d>",
! 				       seq_typename.c_str (), length, traits);
! 	else
! 		tmp = g_strdup_printf (IDL_IMPL_NS "::CompoundUnboundedSeq< %s, %s >",
! 				       seq_typename.c_str (), traits);
! 	
! 	g_free (traits);
! 	retval = tmp;
! 	g_free (tmp);
! 	
! 	return retval;
  }
  	
  string
diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_compound_seq.h ./orbitcpp/orb-cpp/orbitcpp_compound_seq.h
*** ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_compound_seq.h	Sun Feb  9 00:16:00 2003
--- ./orbitcpp/orb-cpp/orbitcpp_compound_seq.h	Wed Mar 26 14:02:11 2003
***************
*** 33,44 ****
  
  namespace _orbitcpp {
  
!     template<typename CPPElem>
!     class CompoundSeqBase: public SequenceBase<typename CPPElem::SeqTraits::value_t,
! 	typename CPPElem::SeqTraits::c_value_t,
!         typename CPPElem::SeqTraits::c_seq_t>
      {
! 	typedef typename CPPElem::SeqTraits  traits_t;
  	typedef typename traits_t::value_t   value_t;
  	typedef typename traits_t::c_value_t c_value_t;
  	typedef typename traits_t::c_seq_t   c_seq_t;
--- 33,66 ----
  
  namespace _orbitcpp {
  
!     template <class CPPElem, class CElem, class CElemSeq, CORBA_TypeCode seq_typecode>
!     struct seq_seq_traits {
! 	typedef CPPElem value_t;
! 	typedef CElem c_value_t;
! 	typedef CElemSeq c_seq_t;
! 	static c_seq_t* alloc_c () {
! 	    return (c_seq_t *)ORBit_small_alloc (seq_typecode);
! 	}
! 
! 	static c_value_t* alloc_c_buf (CORBA::ULong l) {
! 	    return (c_value_t *)ORBit_small_allocbuf(seq_typecode, l);
! 	}						
! 	static void pack_elem (const value_t &cpp_elem, c_value_t &c_elem)
! 	{
! 	    cpp_elem._orbitcpp_pack(c_elem);
! 	}
!         static void unpack_elem (value_t &cpp_elem, const c_value_t &c_elem)
!         {
! 	    cpp_elem._orbitcpp_unpack(c_elem);
!         }
!     };
! 
!     template<typename CPPElem, typename SeqTraits>
!     class CompoundSeqBase: public SequenceBase<typename SeqTraits::value_t,
! 	typename SeqTraits::c_value_t,
!         typename SeqTraits::c_seq_t>
      {
! 	typedef SeqTraits  traits_t;
  	typedef typename traits_t::value_t   value_t;
  	typedef typename traits_t::c_value_t c_value_t;
  	typedef typename traits_t::c_seq_t   c_seq_t;
***************
*** 46,52 ****
  	typedef SequenceBase<value_t, c_value_t, c_seq_t> Super;
  	typedef Super super_t;
  	
! 	typedef CompoundSeqBase<CPPElem> self_t;
  
  	typedef typename Super::size_t   size_t;
  	typedef typename Super::index_t  index_t;
--- 68,74 ----
  	typedef SequenceBase<value_t, c_value_t, c_seq_t> Super;
  	typedef Super super_t;
  	
! 	typedef CompoundSeqBase<CPPElem, SeqTraits> self_t;
  
  	typedef typename Super::size_t   size_t;
  	typedef typename Super::index_t  index_t;
***************
*** 91,104 ****
  	}
      };
      
!     template<typename CPPElem>
!     class CompoundUnboundedSeq: public CompoundSeqBase<CPPElem>
      {
! 	typedef typename CPPElem::SeqTraits  traits_t;
  	typedef typename traits_t::c_value_t c_value_t;
  	typedef typename traits_t::c_seq_t   c_seq_t;
  	
! 	typedef CompoundSeqBase<CPPElem> Super;
  	typedef typename Super::value_t value_t;
  	typedef SequenceBase<value_t, c_value_t, c_seq_t> super_t;
  	
--- 113,126 ----
  	}
      };
      
!     template<typename CPPElem, typename SeqTraits=typename CPPElem::SeqTraits>
!     class CompoundUnboundedSeq: public CompoundSeqBase<CPPElem, SeqTraits>
      {
! 	typedef SeqTraits  traits_t;
  	typedef typename traits_t::c_value_t c_value_t;
  	typedef typename traits_t::c_seq_t   c_seq_t;
  	
! 	typedef CompoundSeqBase<CPPElem, SeqTraits> Super;
  	typedef typename Super::value_t value_t;
  	typedef SequenceBase<value_t, c_value_t, c_seq_t> super_t;
  	
***************
*** 151,165 ****
  	}
      };
      
!     template<typename CPPElem, CORBA::ULong max>
!     class CompoundBoundedSeq: public CompoundSeqBase<CPPElem>
      {
! 	typedef typename CPPElem::SeqTraits traits_t;
  	typedef typename traits_t::value_t  value_t;
  	typedef typename traits_t::c_elem_t c_value_t;
  	typedef typename traits_t::c_seq_t  c_seq_t;
  	
! 	typedef CompoundSeqBase<value_t> Super;
  	typedef Super super_t;
  	
  	typedef typename Super::size_t   size_t;
--- 173,187 ----
  	}
      };
      
!     template<typename CPPElem, CORBA::ULong max, typename SeqTraits=typename CPPElem::SeqTraits>
!     class CompoundBoundedSeq: public CompoundSeqBase<CPPElem, SeqTraits>
      {
! 	typedef SeqTraits traits_t;
  	typedef typename traits_t::value_t  value_t;
  	typedef typename traits_t::c_elem_t c_value_t;
  	typedef typename traits_t::c_seq_t  c_seq_t;
  	
! 	typedef CompoundSeqBase<value_t, SeqTraits> Super;
  	typedef Super super_t;
  	
  	typedef typename Super::size_t   size_t;
diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_sequence.h ./orbitcpp/orb-cpp/orbitcpp_sequence.h
*** ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_sequence.h	Sun Feb  9 00:16:01 2003
--- ./orbitcpp/orb-cpp/orbitcpp_sequence.h	Wed Mar 26 13:33:05 2003
***************
*** 46,51 ****
--- 46,52 ----
  	
  	typedef CORBA::ULong  size_t;
  	typedef CORBA::ULong  index_t;
+ 
  	
      protected:
  	size_t   _max;
diff -r -C 3 ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_simple_seq.h ./orbitcpp/orb-cpp/orbitcpp_simple_seq.h
*** ../orig/orbitcpp-1.3.5/orbitcpp/orb-cpp/orbitcpp_simple_seq.h	Sun Feb  9 00:16:01 2003
--- ./orbitcpp/orb-cpp/orbitcpp_simple_seq.h	Wed Mar 26 11:04:23 2003
***************
*** 179,184 ****
--- 179,198 ----
  	    _length = new_length;
  	}
      };
+ 
+     template <class CPPElem, class CElem, class CElemSeq, CORBA_TypeCode seq_typecode>
+     struct enum_seq_traits {
+ 	typedef CPPElem value_t;
+ 	typedef CElem c_value_t;
+ 	typedef CElemSeq c_seq_t;
+ 	static c_seq_t* alloc_c () {
+ 	    return (c_seq_t *)ORBit_small_alloc (seq_typecode);
+ 	}
+ 
+ 	static c_value_t* alloc_c_buf (CORBA::ULong l) {
+ 	    return (c_value_t *)ORBit_small_allocbuf(seq_typecode, l);
+ 	}						
+     };
      
  } // namespace _orbitcpp
  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]