コード例 #1
0
ファイル: xbe_string.cpp プロジェクト: diorahman/opensplice
void be_string::GenerateTypedefs
(
   const DDS_StdString & /*scope*/ ,
   const be_typedef& alias,
   be_ClientHeader& source
)
{
   ostream & os = source.Stream();
   be_Tab tab(source);

   if (m_typecode->kind == DDS::tk_string)
   {
      // YO BEN should read "DDS::Char*" from some central place; violates OAOO
      os << tab << "typedef DDS::Char* " << alias.LocalName() << ";" << nl;
      os << tab << "typedef "
      << (const char*)BE_Globals::CorbaScope("String_var") << " "
      << alias.LocalName() << DDSVarExtension << ";" << nl;
      os << tab << "typedef "
      << (const char*)BE_Globals::CorbaScope("String_out") << " "
      << alias.LocalName() << DDSOutExtension << ";" << nl;
   }
   else
   {
      // YO BEN should read "DDS::WChar*" from some central place; violates OAOO
      os << tab << "typedef DDS::WChar* " << alias.LocalName() << ";" << nl;
      os << tab << "typedef "
      << (const char*)BE_Globals::CorbaScope("WString_var") << " "
      << alias.LocalName() << DDSVarExtension << ";" << nl;
      os << tab << "typedef "
      << (const char*)BE_Globals::CorbaScope("WString_out") << " "
      << alias.LocalName() << DDSOutExtension << ";" << nl;
   }
}
コード例 #2
0
ファイル: xbe_sequence.cpp プロジェクト: cynron/opensplice
void be_sequence::GenerateAuxTypes (be_ClientHeader & source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);
   DDS_StdString baseName = BaseTypeName ();
   DDS_StdString seqName = localName;
   DDS_StdString varName = localName + "_var";
   DDS_StdString outName = localName + "_out";
   DDS_StdString templateBase = "DDS_DCPSSequence";
   pbbool wideString = pbfalse;

   if (isStringSeq)
   {
      AST_Type* astbt = be_typedef::_astBase (base_type ());
      be_string* sbt = be_string::_narrow (astbt);
      wideString = sbt->IsWide ();
   }

   if (isStringSeq && !IsBounded ())
   {
      templateBase = wideString ? "DDS_DCPSUWStrSeq" : "DDS_DCPSUStrSeq";
   }

   os << tab << "typedef " << templateBase << "_var < " << seqName << "> "
      << varName << ";" << nl;
   os << tab << "typedef " << templateBase << "_out < " << seqName << "> "
      << outName << ";" << nl;
}
コード例 #3
0
ファイル: xbe_type.cpp プロジェクト: xrl/opensplice_dds
void be_Type::GenerateStreamOps (be_ClientHeader& source)
{
   ostream & os = source.Stream ();
   be_Tab tab (source);

   // insertion

   os << tab << DLLMACRO << "inline void" << nl
   << "IOP::put(DDS::Codec::OutStream& os, const "
   << ScopedName() << "& v" << XBE_Ev::arg (XBE_ENV_ARGN) << ")" << nl;
   os << "{" << nl;
   tab.indent();
   os << tab << "DDS::Codec::Param putArg = ";
   os << "{ " << Scope(TypeCodeTypeName()) << ", ";
   os << "(" << TypeName() << "*)" << "&v, DDS::PARAM_IN ";
   os << "};" << nl;
   os << tab << "os.put (&putArg, 1" << XBE_Ev::arg (XBE_ENV_VARN) << ");" << nl;
   tab.outdent();
   os << "}" << nl << nl;

   //
   // extraction
   //
   os << DLLMACRO << "inline void" << nl
   << "IOP::get(DDS::Codec::InStream& is, "
   << ScopedName() << "& v" << XBE_Ev::arg (XBE_ENV_ARGN) << ")" << nl;
   os << "{" << nl;
   tab.indent();
   os << tab << "DDS::Codec::Param getArg = ";
   os << "{ " << Scope(TypeCodeTypeName()) << ", ";
   os << "&v, DDS::PARAM_OUT };" << nl;
   os << tab << "is.get (&getArg, 1" << XBE_Ev::arg (XBE_ENV_VARN) << ");" << nl;
   tab.outdent();
   os << "}" << nl << nl;
}
コード例 #4
0
ファイル: xbe_structure.cpp プロジェクト: alex1818/opensplice
void be_structure::GenerateAuxTypes (be_ClientHeader& source)
{
   if (BE_Globals::isocpp_new_types)
     return;

   DDS_StdString varName = LocalName () + "_var";
   DDS_StdString outName = LocalName () + "_out";
   ostream & os = source.Stream ();
   be_Tab tab (source);

   if (m_isFixedLength)
   {
      os << tab << "typedef DDS_DCPSStruct_var < "
      << LocalName() << "> " << varName << ";" << nl;
      os << tab << "typedef " << LocalName ()
         << "&" << outName << ";" << nl;
   }
   else
   {
      os << tab << "typedef DDS_DCPSStruct_var < "
      << LocalName() << "> " << varName << ";" << nl;
      os << tab << "typedef DDS_DCPSStruct_out < "
      << LocalName() << "> " << outName << ";" << nl;
   }
}
コード例 #5
0
void be_exception::GenerateConvenienceConstructor (be_ClientHeader& source)
{
   ostream & os = source.Stream ();
   const char * argPrefix = "_";
   pbbool first = pbtrue;
   be_Tab tab (source);

   os << tab << LocalName () << " (";

   UTL_Scope * s = (UTL_Scope*)narrow ((long) & UTL_Scope::type_id);
   assert (s);

   // Iterate through decls

   UTL_ScopeActiveIterator *it;

   for
   (
      it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls);
      !it->is_done ();
      it->next ()
   )
   {
      AST_Decl * adecl = it->item();
      assert (adecl);
      be_field * bfield = be_field::_narrow (adecl);
      be_Type * btype;

      if (bfield)
      {
         btype = bfield->get_be_type ();

         if (!first)
         {
            os << ", ";
         }

         first = pbfalse;

         if (btype && btype->IsStringType ())
         {
            // Strings are special case

            os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->InTypeName ());
         }
         else
         {
            os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ());
         }

         os << " " << argPrefix << (char*) bfield->get_local_name ();
      }
   }

   delete it;

   os << ");" << nl;
}
コード例 #6
0
ファイル: xbe_structure.cpp プロジェクト: xrl/opensplice_dds
void
be_structure::GenerateDefaultConstructor(be_ClientHeader& source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);

   os << tab << LocalName() << "()" << nl;
   os << tab << "{" << nl << tab << "}" << nl;
}
コード例 #7
0
ファイル: xbe_structure.cpp プロジェクト: xrl/opensplice_dds
void
be_structure::GenerateMemcpyCopyConstructor(be_ClientHeader& source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);

   os << tab << LocalName() << "(const "
      << LocalName() << "& that)" << nl;
   os << tab << "{" << nl << tab.indent()
      << tab << "memcpy(this, &that, sizeof(" << LocalName() << "));"
      << nl << tab.outdent()
      << tab << "}" << nl;
}
コード例 #8
0
ファイル: xbe_enum.cpp プロジェクト: osrf/opensplice
void
be_enum::GenerateTypedefs( const DDS_StdString& scope,
                           const be_typedef& alias,
                           be_ClientHeader& source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);

   DDS_StdString relTypeName = BE_Globals::RelativeScope(scope, typeName);

   os << tab << "typedef " << (const char*)relTypeName << " "
   << alias.LocalName() << ";" << nl;
}
コード例 #9
0
ファイル: xbe_sequence.cpp プロジェクト: cynron/opensplice
void be_sequence::GeneratePutGetOps (be_ClientHeader& source)
{
   ostream & os = source.Stream ();
   be_Tab tab (source);
   be_predefined_type * prtype = be_predefined_type::_narrow (base_type ());

   //
   // don't generate StreamOps for types that are already in
   // the core
   //

   if ( /* !baseType->IsStringType() && */ // note remove this when replace strseq
      !(prtype &&
        ( (prtype->pt() == AST_PredefinedType::PT_octet) ||
          (prtype->pt() == AST_PredefinedType::PT_char) ||
          (prtype->pt() == AST_PredefinedType::PT_wchar) ||
          (prtype->pt() == AST_PredefinedType::PT_boolean) ) ) )
   {
      os << tab << DLLMACRO << "void " << m_tc_put_val << nl;
      os << tab << "(" << nl;
      tab.indent ();
      os << tab << "DDS::Codec::OutStream & os," << nl;
      os << tab << "const void * arg," << nl;
      os << tab << "DDS::ParameterMode mode" << nl;
      if (XBE_Ev::generate ())
      {
         os << tab << XBE_Ev::arg (XBE_ENV_ARGN, false) << nl;
      }
      tab.outdent ();
      os << tab << ");" << nl << nl;
      os << tab << DLLMACRO << "void " << m_tc_get_val << nl;
      os << tab << "(" << nl;
      tab.indent ();
      os << tab << "DDS::Codec::InStream & is," << nl;
      os << tab << "void * arg," << nl;
      os << tab << "DDS::ParameterMode mode" << nl;
      if (XBE_Ev::generate ())
      {
         os << tab << XBE_Ev::arg (XBE_ENV_ARGN, false) << nl;
      }
      tab.outdent (); //2
      os << tab << ");" << nl << nl;
   }
}
コード例 #10
0
ファイル: xbe_structure.cpp プロジェクト: xrl/opensplice_dds
void
be_structure::GenerateTypedefs( const DDS_StdString &scope,
                                const be_typedef& alias,
                                be_ClientHeader& source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);
   DDS_StdString relTypeName = BE_Globals::RelativeScope(scope, typeName);

   os << tab << "typedef " << relTypeName << " "
   << alias.LocalName() << ";" << nl;
   os << tab << "typedef " << relTypeName << DDSVarExtension << " "
   << alias.LocalName() << DDSVarExtension << ";" << nl;

   if (!m_isFixedLength)
   {
      os << tab << "typedef " << relTypeName << DDSOutExtension << " "
      << alias.LocalName() << DDSOutExtension << ";" << nl;
   }
}
コード例 #11
0
void
be_exception::GenerateMembers(be_ClientHeader& source)
{
   ostream & os = source.Stream();
   pbbool first = pbtrue;
   be_Tab tab(source);

   UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id);
   assert(s);

   // ITERATE THROUGH DECLS
   UTL_ScopeActiveIterator *it;

   for ( it = new UTL_ScopeActiveIterator(s, UTL_Scope::IK_decls);
         !it->is_done();
         it->next())
   {
      AST_Decl * adecl = it->item();

      assert(adecl);

      if (first)
      {
         os << nl << tab << "public: " << nl << nl;
         first = pbfalse;
      }

      be_field * bfield = be_field::_narrow(adecl);

      if (bfield)
      {
         os << tab;
         os << BE_Globals::RelativeScope(
            ScopedName(),
            bfield->StructMemberTypeName());
         os << " " << bfield->get_local_name() << ";" << nl;
      }
   }

   delete it;
}
コード例 #12
0
ファイル: xbe_cppfwd.cpp プロジェクト: xrl/opensplice_dds
void be_CppFwdDecl::Generate (be_ClientHeader& source) const
{
   ostream& os = source.Stream();
   be_Tab tab (source);

   if (m_declType == be_CppFwdDecl::INTERFACE)      
   {
      if (!BE_Globals::ignore_interfaces)
      {
         be_interface::GeneratePtrAndRef (source, m_beType->ScopedName(),
                                          m_beType->LocalName());
         be_interface::GenerateVarOutAndMgr (source, m_beType->ScopedName(),
                                             m_beType->LocalName());
         be_interface_fwd::Generated (m_beType->ScopedName());
      }
   }
   else if (!BE_Globals::ignore_interfaces ||
            !m_beType->IsInterfaceDependant ())
   {
      os << tab << keywords[m_declType] << " " << m_beType->LocalName() << ';' << nl;
   }
}
コード例 #13
0
ファイル: xbe_sequence.cpp プロジェクト: cynron/opensplice
void
be_sequence::GenerateTypedefs(const DDS_StdString &scope,
                              const be_typedef& alias,
                              be_ClientHeader& source)
{
   ostream & os = source.Stream();
   be_Tab tab(source);
   DDS_StdString relTypeName = BE_Globals::RelativeScope(scope, typeName);

   os << tab << "typedef " << relTypeName << " "
   << alias.LocalName() << ";" << nl;
   os << tab << "typedef " << relTypeName << DDSVarExtension
   << " " << alias.LocalName() << DDSVarExtension << ";" << nl;
   os << tab << "typedef " << relTypeName << DDSOutExtension
   << " " << alias.LocalName() << DDSOutExtension << ";" << nl;

   if (anonymous)
   {
      localName = alias.LocalName ();
      anonymous = pbfalse;
      InitializeTypeMap (this);
   }
}
コード例 #14
0
ファイル: xbe_type.cpp プロジェクト: xrl/opensplice_dds
void be_Type::GeneratePutGetOps (be_ClientHeader& source)
{
   ostream & os = source.Stream ();
   be_Tab tab (source);

   // we have to generate even core marshaled ops
   // for use by dependent types, e.g., an
   // array of unions needs the union's ops declared

   // first putval and getval

   os << tab << DLLMACRO << "void " << m_tc_put_val << nl;
   os << tab << "(" << nl;
   tab.indent ();
   os << tab << "DDS::Codec::OutStream & os," << nl;
   os << tab << "const void * arg," << nl;
   os << tab << "DDS::ParameterMode mode" << nl;
   if (XBE_Ev::generate ())
   {
      os << tab << XBE_Ev::arg (XBE_ENV_ARGN, false) << nl;
   }
   tab.outdent ();
   os << tab << ");" << nl << nl;
   os << tab << DLLMACRO << "void " << m_tc_get_val << nl;
   os << tab << "(" << nl;
   tab.indent ();
   os << tab << "DDS::Codec::InStream & is," << nl;
   os << tab << "void * arg," << nl;
   os << tab << "DDS::ParameterMode mode" << nl;
   if (XBE_Ev::generate ())
   {
      os << tab << XBE_Ev::arg (XBE_ENV_ARGN, false) << nl;
   }
   tab.outdent ();
   os << tab << ");" << nl << nl;
}
コード例 #15
0
void be_exception::Generate (be_ClientHeader & source)
{
   if (!Generated ())
   {
      ostream & os = source.Stream ();
      be_Tab tab (source);
      DDS_StdString lname = LocalName ();

      Generated (pbtrue);

      be_root::AddGlobalDeclarations (this);
      be_root::AddAnyOps (*this);
      be_root::AddStreamOps (*this);
      be_root::AddTypedef (*this);
      be_root::AddTypecode (*this);

      GenerateOpenClassDefinition (source);
      GenerateClassDeclarations (source);
      SetAccess (source, CA_PUBLIC);

      // now define nested types

      be_CodeGenerator::Generate (source);

      // generate _downcast

      os << tab << "static " << lname << "* _downcast ("
         << "DDS::Exception *);" << nl;
      os << tab << "static const " << lname << "* _downcast ("
         << "const DDS::Exception *);" << nl;

      // generate factory and builder

      os << tab << "static DDS::Exception * factory ();" << nl;
      os << tab << "static DDS::ExceptionInitializer m_initializer;" << nl << nl;

      // generate inline default constructor

      os << tab << lname << " () {};" << nl;

      // generate convenience constructor

      if (nmembers())
      {
         GenerateConvenienceConstructor (source);
      }

      // generate copy constructor

      os << tab << lname << " (const " << lname << " &);" << nl;

      // generate assignment operator

      os << tab << lname << "& operator = " << "(const " << lname << " &);" << nl;

      // generate duplicate

      os << tab << "virtual DDS::Exception * _clone () const;" << nl;

      // generate raise

      os << tab << "virtual void _raise (" << XBE_Ev::arg (XBE_ENV_ARG1)
         << ") const;" << nl;

      // generate name

      os << tab << "virtual const char * _name () const { return m_name; };" << nl;

      // generate repository id

      os << tab << "virtual const char * _rep_id () const { return m_id; };" << nl;

      // generate virtual destructor

      os << tab << "virtual ~" << lname << " () {}" << nl;

      GenerateMembers (source);
      SetAccess (source, CA_PRIVATE);

      os << tab << "static const char * m_name;" << nl;
      os << tab << "static const char * m_id;" << nl;

      GenerateCloseClassDefinition (source);

      be_root::GenerateDependants
      (
         source,
         SequenceMemberTypeName (),
         EnclosingScope ()
      );
   }
}
コード例 #16
0
ファイル: xbe_root.cpp プロジェクト: osrf/opensplice
void be_root::Generate (be_ClientHeader & source)
{
   be_CppFwdDecl::GenerateAllWithinScope (source, be_CppEnclosingScope());

   ostream& os = source.Stream ();
   TList<be_Type *>::iterator bit;
   TList<be_exception *>::iterator git;

   for (bit = fwdDecls.begin(); bit != fwdDecls.end(); bit++)
   {
      (*bit)->GenerateFwdDecls(source);
   }

   os << nl;
   GenerateGlobalTypes (source);
   GenerateGlobalDecls (source);

   g_generatorList.GenerateGlobal (source);

   if (BE_Globals::gen_externalization)
   {
      os << nl;

      for (bit = streamOps.begin(); bit != streamOps.end(); bit++)
      {
         (*bit)->GenerateStreamOps(source);
      }
   }

   os << nl;

   for (git = globalDecls.begin(); git != globalDecls.end(); git++)
   {
      (*git)->GenerateGlobalDecls (source);
   }

   os << nl;

   for (bit = typedefs.begin(); bit != typedefs.end(); bit++)
   {
      (*bit)->GenerateGlobalTypedef (source);
   }

   os << nl;

   if(BE_Globals::isocpp_test_methods)
   {
      //Generate file to stop missing file error
      DDS_StdString BaseFilename;
      BaseFilename = StripExtension(source.Filename());
      BaseFilename += "_testmethod.h";
      be_Source testsource;
      if(!testsource.Open(BaseFilename))
        cerr << "Cannot open: " << BaseFilename << endl;
      testsource.Close();

      //os << nl << "#ifndef " << Ifndefize(BE_Globals::ClientHeaderFilename + "DCPS");
      os << nl << "#ifndef " << Ifndefize(StripExtension(FindFilename(source.Filename())) + "DCPS.h");
      os << nl << "#ifndef " << Ifndefize(StripExtension(FindFilename(source.Filename())) + "_testmethod.h");
      os << nl << "#define " << Ifndefize(StripExtension(FindFilename(source.Filename())) + "_testmethod.h");
      os << nl << "#include \"" << StripExtension(FindFilename(source.Filename())) + "_testmethod.h" << "\"";
      os << nl << "#endif " << nl << "#endif" << nl;

   }

   if (BE_Globals::lite)
   {
       DDS_StdString BaseFilename;
       BaseFilename = StripExtension(source.Filename());

       os << "\n#include \"" << BaseFilename << "-lite.h" << "\"" << nl;
   }

   os << nl << "#endif" << nl;
   source.Close();
}
コード例 #17
0
ファイル: xbe_sequence.cpp プロジェクト: cynron/opensplice
void be_sequence::GenerateSequence (be_ClientHeader & source)
{
   ostream & os = source.Stream ();
   be_Tab tab (source);
   DDS_StdString elemName;
   pbbool wideString = pbfalse;

   if (isInterfaceSeq || isValueSeq)
   {
      elemName = BE_Globals::RelativeScope(enclosingScope, baseType->ScopedName());
   }
   else
   {
      elemName = BE_Globals::RelativeScope(enclosingScope, baseTypeName);

      if (isStringSeq)
      {
         AST_Type* astbt = be_typedef::_astBase(base_type());
         be_string* sbt = be_string::_narrow(astbt);
         wideString = sbt->IsWide();
      }
   }

   DDS_StdString FileClassname;
   DDS_StdString charFileClassname;
   DDS_StdString boolFileClassname;

   FileClassname = elemName;
   charFileClassname = DDS_StdString("DDSChar");
   boolFileClassname = DDS_StdString("DDSBoolean");

   os << tab << "struct " << localName << "_uniq_ {};" << nl;

   if (IsBounded())
   {
      // Bounded sequence types

      if (baseType->IsFixedLength())
      {
         be_predefined_type * pdt = be_predefined_type::_narrow(base_type());

         os << tab << "typedef DDS_DCPSBFLSeq < " << elemName
            << ", " << FileClassname << ", " << maxSize << "> " << localName << ";" << nl;
      }
      else if (isStringSeq)
      {
         if (wideString)
         {
            os << tab << "typedef DDS_DCPSBWStrSeq < " << maxSize << "> "
            << localName << ";" << nl;
         }
         else
         {
            os << tab << "typedef DDS_DCPSBStrSeq < " << maxSize << "> "
            << localName << ";" << nl;
         }
      }
      else if (isInterfaceSeq)
      {
         os << tab << "typedef DDS_DCPSBObjSeq < " << elemName << ", struct "
            << localName << "_uniq_, " << maxSize << "> " << localName << ";"
            << nl;
      }
      else if (isValueSeq)
      {
         os << tab << "typedef DDS_DCPSBValSeq < " << elemName
         << ", " << maxSize << "> " << localName << ";" << nl;
      }
      else
      {
         os << tab << "typedef DDS_DCPSBVLSeq < " << elemName
         << ", " << maxSize << "> " << localName << ";" << nl;
      }
   }
   else
   {
      // Unbounded sequence types

      if (baseType->IsFixedLength ())
      {
         os << tab << "typedef DDS_DCPSUFLSeq < " << elemName << ", struct "
            << localName << "_uniq_> " << localName << ";" << nl;
      }
      else if (isStringSeq)
      {
         if (wideString)
         {
            os << tab << "typedef DDS_DCPSUWStrSeqT <struct " << localName
               << "_uniq_> " << localName << ";" << nl;
         }
         else
         {
            os << tab << "typedef DDS_DCPSUStrSeqT <struct " << localName 
               << "_uniq_> " << localName << ";" << nl;
         }
      }
      else if (isInterfaceSeq)
      {
         os << tab << "typedef DDS_DCPSUObjSeq < " << elemName << ", struct "
            << localName << "_uniq_> " << localName << ";" << nl;
      }
      else if (isValueSeq)
      {
         os << tab << "typedef DDS_DCPSUValSeq < " << elemName
            << "> " << localName << ";" << nl;
      }
      else
      {
         os << tab << "typedef DDS_DCPSUVLSeq < " << elemName << ", struct "
            << localName << "_uniq_> " << localName << ";" << nl;
      }
   }
}
コード例 #18
0
ファイル: xbe_structure.cpp プロジェクト: alex1818/opensplice
void be_structure::Generate (be_ClientHeader& source)
{
   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (!Generated())
   {
      be_root::AddAnyOps(*this);
      be_root::AddPutGetOps(*this);
      be_root::AddStreamOps(*this);
      be_root::AddTypedef(*this);
      be_root::AddTypecode(*this);

      ostream & os = source.Stream();
      DDS_StdString scopedName = ScopedName();
      DDS_StdString relativeName;
      be_Tab tab(source);
      TList<be_field *>::iterator mit;
      be_field * field;

      Generated (pbtrue);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());

      g_cppScopeStack.Push(m_cppType);

      // struct definition

      os << nl;
      os << tab << (BE_Globals::isocpp_new_types ? "class " : "struct ") << DLLMACRO << LocalName ()
                <<  (BE_Globals::isocpp_new_types ? " OSPL_DDS_FINAL" : "") << nl;
      os << tab << "{" << nl;
      if (BE_Globals::isocpp_new_types)
        os << tab << "public:" << nl;

      source.Indent();

      // declare nested types

      source.Indent();
      be_CodeGenerator::Generate(source);

      // member accessor functions for isocpp new types
      if (BE_Globals::isocpp_new_types)
      {
        /** @internal
         * @todo OSPL-3369 Repetition; the sort of code people go to hell
         * for (rightfully); is_sequency is already evideantally a stupid name; &c... */
        // Constructors
        if (m_fields.size() > 0)
        {
          os << tab << LocalName() << "() {}" << nl;
          os << tab << "explicit " << LocalName() << "(" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            bool is_sequency = !(field->get_be_type()->IsPrimitiveType()
                                  || field->get_be_type()->IsEnumeratedType());
            relativeName = BE_Globals::RelativeScope
                (scopedName, field->StructMemberTypeName ());
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << (is_sequency ? "const " : "") << relativeName
                << (is_sequency ? "& " : " ") << field->get_local_name();
            if (mit == final_field)
              os << ")";
            else
              os <<"," << nl;
          }
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(" << field->get_local_name() << ")" << (mit == final_field ? " {}" : ",") << nl;
          }
        }
        // C++ 11 move constructor, copy consructor, and assignement ops
        source.Outdent();
        os << "#ifdef OSPL_DDS_CXX11" << nl;
        os << "#  ifdef OSPL_CXX11_NO_FUNCTION_DEFAULTS" << nl;
        source.Indent();
        os << tab << LocalName() << "(const " << LocalName() << "& _other)" << nl;
        if (m_fields.size() > 0)
        {
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(_other." << field->get_local_name() << "_)" << (mit == final_field ? "" : ",") << nl;
          }
        }
        os << tab << "{}" << nl;
        os << tab << LocalName() << "(" << LocalName() << "&& _other)" << nl;
        if (m_fields.size() > 0)
        {
          os << tab << ":" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_(::std::move(_other." << field->get_local_name() << "_))" << (mit == final_field ? "" : ",") << nl;
          }
        }
        os << tab << "{}" << nl;
        os << tab <<  LocalName() << "& operator=(" << LocalName() << "&& _other)" << nl;
        os << tab << "{" << nl ;
        if (m_fields.size() > 0)
        {
          os << tab << tab << "if (this != &_other)" << nl;
          os << tab << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_ = ::std::move(_other." << field->get_local_name() << "_);" << nl;
          }
          os << tab << tab << "}" << nl;
        }
        os << tab << tab << "return *this;" << nl;
        os << tab << "}" << nl;
        os << tab <<  LocalName() << "& operator=(const "  << LocalName() << "& _other)" << nl;
        os << tab << "{" << nl ;
        if (m_fields.size() > 0)
        {
          os << tab << tab << "if (this != &_other)" << nl;
          os << tab << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;
            os << tab << tab << tab << field->get_local_name() << "_ = _other." << field->get_local_name() << "_;" << nl;
          }
          os << tab << tab << "}" << nl;
        }
        os << tab << tab << "return *this;" << nl;
        os << tab << "}" << nl;
        source.Outdent();
        os << "#  else" << nl;
        source.Indent();
        os << tab << LocalName() << "(const " << LocalName() << "& _other) = default;" << nl;
        os << tab << LocalName() << "(" << LocalName() << "&& _other) = default;" << nl;
        os << tab <<  LocalName() << "& operator=(" << LocalName() << "&& _other) = default;" << nl;
        os << tab <<  LocalName() << "& operator=(const "  << LocalName() << "& _other) = default;" << nl;
        source.Outdent();
        os << "#  endif" << nl;
        os << "#endif" << nl;
        source.Indent();
        for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
        {
          field = *mit;
          bool is_sequency = !(field->get_be_type()->IsPrimitiveType()
                                || field->get_be_type()->IsEnumeratedType());
          relativeName = BE_Globals::RelativeScope
              (scopedName, field->StructMemberTypeName ());
          // const get accessor
          os << tab << (is_sequency ? "const " : "") << relativeName << (is_sequency ? "& " : " ")
              << field->get_local_name() << "() const { return this->" << field->get_local_name() << "_; }" << nl;
          // reference get accessor
          os << tab << relativeName << "& "
              << field->get_local_name() << "() { return this->" << field->get_local_name() << "_; }" << nl;
          // const set accessor
          os << tab << "void "
              << field->get_local_name() << (is_sequency ? "(const " : "(") << relativeName
              << (is_sequency ? "&" : "") << " _val_) { this->" << field->get_local_name() << "_ = _val_; }" << nl;
          source.Outdent();
          if (!(field->get_be_type()->IsPrimitiveType()
                  && !field->get_be_type()->IsEnumeratedType())) {
              os << "#ifdef OSPL_DDS_CXX11" << nl;
              source.Indent();
              // C++ 11 move assignement op
              os << tab << "void "
                      << field->get_local_name() <<  "(" << relativeName << "&& _val_) { this->" << field->get_local_name() << "_ = _val_; }" << nl;
              source.Outdent();
              os << "#endif" << nl;
          }
          source.Indent();
        }
      }

      if (BE_Globals::gen_equality)
      {
          os << tab << "bool operator==(const " << LocalName() << "& _other) const" <<
            nl << tab << "{" << nl << tab << tab << "return ";
          DDS_StdString relName;
          for(mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
            field = *mit;
            relName = BE_Globals::RelativeScope
            (scopedName, field->get_local_name());
            TList<be_field *>::iterator final_field = m_fields.end();
            --final_field;

            if(mit != m_fields.begin())
                os << tab << tab;

            os  << relName << (BE_Globals::isocpp_new_types ? "_" : "")
                << " == _other."
                << relName << (BE_Globals::isocpp_new_types ? "_" : "")
                << (mit != final_field ? " &&" : ";") << nl;

          }
          os << tab << "}" << nl;

          os << tab << "bool operator!=(const " << LocalName() << "& other) const" <<
                nl << tab << "{" << nl << tab << tab << "return !(*this == other);"
                << nl << tab << "}" << nl;

      }

      // member declarations
      for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
      {
         field = *mit;
         relativeName = BE_Globals::RelativeScope
            (scopedName, field->StructMemberTypeName ());
         os << tab << relativeName << " "
            << field->get_local_name() << (BE_Globals::isocpp_new_types ? "_" : "") << ";" << nl;
      }

      source.Outdent();
      source.Outdent();

      source.Stream() << tab << "};" << nl << nl;
      g_cppScopeStack.Pop();



      if (BE_Globals::isocpp_test_methods)
      {
          //Get base filename and append _testmethod.h
          DDS_StdString BaseFilename;
          BaseFilename = StripExtension(source.Filename());
          BaseFilename += "_testmethod.h";

          //Open or append to file
          be_Source testsource;
          ostream & ts = testsource.Stream();
          if(!testsource.Open(BaseFilename))
              cerr << "Cannot open: " << BaseFilename << endl;

          testsource.Indent();
          ts <<  "namespace {" << nl
                              <<  "template <>" << nl <<  "::std::vector< ::"
                              << ScopedName() <<  " > generate_test_values< ::"
                              << ScopedName() << " >()"  << nl
                              << "{" << nl;

          ts << tab << "::std::vector< ::" << ScopedName() << " > values;" << nl
                              << tab << "::" << ScopedName() << " next;" << nl
                              << tab << "::std::size_t biggest = 0;" << nl;

          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
             field = *mit;
             relativeName = field->StructMemberTypeName ();

             ts << tab <<"::std::vector< " << field->StructMemberTypeName() << " > " << field->get_local_name() << "_ = generate_test_values< "
                                 << field->StructMemberTypeName() << " >();" << nl;
             ts << tab << "if(" << field->get_local_name() << "_.size() > biggest)"
                                 << nl << tab << tab << "biggest = " << field->get_local_name() << "_.size();"
                                 << nl;
          }
          ts << tab << "for(::std::size_t i = 0; i < biggest; ++i)" << nl << tab << "{" << nl;
          for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
          {
             field = *mit;
             relativeName = BE_Globals::RelativeScope(scopedName, field->StructMemberTypeName ());

             ts << tab << tab << "next." << field->get_local_name() << "_ = " << field->get_local_name()
                << "_[i < " << field->get_local_name() << "_.size()? i : " << field->get_local_name()
                << "_.size() -1];" << nl;
          }
          ts << tab << tab << "values.push_back(next);" << nl
             << tab << "}" << nl
             << tab << "return values;" << nl;
          ts << "} }" << nl << nl;
          testsource.Outdent();
          testsource.Close();
      }

      GenerateAuxTypes (source);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());
   }
}
コード例 #19
0
ファイル: xbe_enum.cpp プロジェクト: osrf/opensplice
void
be_enum::Generate(be_ClientHeader& source)
{
   if (!Generated())
   {
      UTL_ScopeActiveIterator* i = new UTL_ScopeActiveIterator(this, IK_decls);
      ostream & os = source.Stream();
      unsigned long expectedValue = 0;
      be_Tab tab(source);
      AST_Decl * d;

      Generated(pbtrue);

      os << tab << "enum " << *local_name() << nl;
      os << tab << "{" << nl;
      tab.indent();

      while (!(i->is_done()))
      {
         d = i->item ();
         if (d)
         {
            be_enum_val * ev = (be_enum_val*) d->narrow ((long) & be_enum_val::type_id);

            if (ev)
            {
               os << tab << *ev->local_name();

               if (ev->Value() != expectedValue)
               {
                  expectedValue = ev->Value();
                  os << " = " << expectedValue;
               }

               expectedValue++;

               i->next();

               if (!(i->is_done()))
               {
                  os << ",";
               }

               os << nl;
            }
            else
            {
               DDSError(NameToString(name()) + " contains non-enum val");
               assert(pbfalse);
            }
         }
         else
         {
            DDSError(NameToString(name()) + " declaration is corrupted");
            assert(pbfalse);
         }
      }

      //os << tab << "DDS_DCPS_FORCE_ENUM32(__" << *local_name() << ")" << nl;

      tab.outdent();
      os << tab << "};" << nl;

      delete i;

      // GENERATE STREAMING OPERATORS
      be_root::AddAnyOps(*this);
      be_root::AddPutGetOps(*this);
      be_root::AddStreamOps(*this);
      be_root::AddTypedef(*this);
      be_root::AddTypecode(*this);
   }
}
コード例 #20
0
ファイル: xbe_structure.cpp プロジェクト: xrl/opensplice_dds
void be_structure::Generate (be_ClientHeader& source)
{
   if (BE_Globals::ignore_interfaces && IsInterfaceDependant ())
   {
      return;
   }

   if (!Generated())
   {
      be_root::AddAnyOps(*this);
      be_root::AddPutGetOps(*this);
      be_root::AddStreamOps(*this);
      be_root::AddTypedef(*this);
      be_root::AddTypecode(*this);

      ostream & os = source.Stream();
      DDS_StdString scopedName = ScopedName();
      DDS_StdString relativeName;
      be_Tab tab(source);
      TList<be_field *>::iterator mit;
      be_field * field;

      Generated (pbtrue);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());

      g_cppScopeStack.Push(m_cppType);

      // struct definition

      os << nl;
      os << tab << "struct " << DLLMACRO << LocalName () << nl;
      os << tab << "{" << nl;
      source.Indent ();

      // declare nested types

      be_CodeGenerator::Generate(source);

      // member declarations

      for (mit = m_fields.begin(); mit != m_fields.end(); mit++)
      {
         field = *mit;
         relativeName = BE_Globals::RelativeScope
            (scopedName, field->StructMemberTypeName ());
         os << tab << relativeName << " "
            << field->get_local_name() << ";" << nl;
      }

      source.Outdent();

      source.Stream() << tab << "};" << nl << nl;

      g_cppScopeStack.Pop();

      GenerateAuxTypes (source);

      be_root::GenerateDependants(source, SequenceMemberTypeName(),
                                  EnclosingScope());
   }
}