⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psdl_interface_visitor.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include "PSDL_Interface_Visitor.h"
#include "PSDL_Stream.h"

ACE_RCSID (PSS,
           PSDL_Interface_Visitor,
           "PSDL_Interface_Visitor.cpp,v 1.3 2003/05/06 19:58:52 ossama Exp")

TAO_PSDL_Interface_Visitor::TAO_PSDL_Interface_Visitor (void)
  : forward_dcl_ (0),
    interface_name_ ()
{
  // constructor.
}

TAO_PSDL_Interface_Visitor::~TAO_PSDL_Interface_Visitor (void)
{
  // destructor.
}

int
TAO_PSDL_Interface_Visitor::visit_identifier (TAO_PSDL_Identifier *identifier)
{
  this->identifiers_.size (1);
  this->count_ = 0;

  // Save the identifier.
  this->identifiers_ [this->count_] = identifier->value ();

  return 0;
}

int
TAO_PSDL_Interface_Visitor::visit_forward_dcl (TAO_PSDL_Forward_Dcl *forward_dcl)
{
  if (forward_dcl->identifier ()->accept (this) == -1)
    return -1;

  this->interface_name_ = this->identifiers_[this->count_];

  // Get a pointer to PSDL_Stream of the stub header.
  TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();

  ps_sh->reset ();

  *ps_sh << "class " << this->interface_name_ << ";";
  ps_sh->nl ();

  this->forward_dcl_ = 1;
  this->print_for_forward_dcl ();

  return 0;
}

int
TAO_PSDL_Interface_Visitor::visit_interface_dcl (TAO_PSDL_Interface_Dcl *interface_dcl)
{
  if (interface_dcl->interface_header ()->accept (this) == -1)
    return -1;

  if (interface_dcl->interface_body () != 0)
    {
      if (interface_dcl->interface_body ()->accept (this) == -1)
        return -1;
    }

  // The generated code for interfaces.
  this->print_end_for_interface ();
  return 0;
}

int
TAO_PSDL_Interface_Visitor::visit_interface_header (TAO_PSDL_Interface_Header *interface_header)
{
  if (interface_header->identifier ()->accept (this) == -1)
    return -1;

  this->interface_name_ = this->identifiers_[this->count_];
  TAO_PSDL_Scope::instance ()->set_interface_name (this->interface_name_);
  this->print_class_for_interface ();

  if (interface_header->type () != 0)
    {
      if (interface_header->type ()->accept (this) == -1)
        return -1;
    }

  if (interface_header->interface_inheritance_spec () != 0)
    {
      if (interface_header->interface_inheritance_spec ()->accept (this) == -1)
        return -1;
    }

  return 0;
}

void
TAO_PSDL_Interface_Visitor::print_for_forward_dcl (void)
{
  // Get a pointer to PSDL_Stream of the stub header.
  TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();

  ps_sh->reset ();

  ps_sh->nl ();

  ACE_CString name_space = TAO_PSDL_Scope::instance ()->get_name_space ();

  *ps_sh << "#if !defined (_" << name_space << "_" << this->interface_name_
         << "___PTR_CH_)";  ps_sh->nl ();

  *ps_sh << "#define _" << name_space << "_"
         << this->interface_name_ << "___PTR_CH_";

  ps_sh->nl ();
  ps_sh->nl ();

  if (this->forward_dcl_ != 1)
    {
      *ps_sh << "class " << this->interface_name_ << ";";  ps_sh->nl ();
    }

  *ps_sh << "typedef " << this->interface_name_ << "*"
         << this->interface_name_ << "_ptr;";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "#endif /* end #if !defined */" << "\n\n";  ps_sh->nl ();

  *ps_sh << "#if !defined (_" << name_space << "_"
         << this->interface_name_ << "___VAR_CH_)";
  ps_sh->nl ();

  *ps_sh << "#define _" << name_space << "_"
         << this->interface_name_ << "___VAR_CH_";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "class " << this->interface_name_.c_str ()
         << "_var : public TAO_Base_Var";  ps_sh->nl ();

  *ps_sh << "{";
  ps_sh->nl ();
  ps_sh->incr_indent (0);

  *ps_sh << "public:";
  ps_sh->nl ();

  *ps_sh  <<  this->interface_name_ << "_var (void);"
          << "// default constructor";
  ps_sh->nl ();

  *ps_sh  <<  this->interface_name_ << "_var (" << this->interface_name_
          << "_ptr p) : ptr_ (p) {}";
  ps_sh->nl ();

  *ps_sh  <<  this->interface_name_ << "_var (const "
          << this->interface_name_
          << "_var &);" << "// copy constructor";
  ps_sh->nl ();

  *ps_sh << " ~" << this->interface_name_ << "_var (void"
         << "); // destructor";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_var"
         << "&operator= (" << this->interface_name_
         << "_ptr);";  ps_sh->nl ();

  *ps_sh  << this->interface_name_ << "_var"
          << "&operator= (const " << this->interface_name_
          << "_var &);";
  ps_sh->nl ();

  *ps_sh  << this->interface_name_
          << "_ptr operator-> (void) const;";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "operator const "
         << this->interface_name_ << "_ptr &() const;";  ps_sh->nl ();

  *ps_sh << "operator "
         << this->interface_name_ << "_ptr &();";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "// in, inout, out, _retn";  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr in (void) const;";
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr &inout (void);";
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr &out (void);";
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr _retn (void);";
  ps_sh->nl ();

  *ps_sh <<  this->interface_name_ << "_ptr ptr (void) const;";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "// Hooks used by template sequence and object manager classes";
  ps_sh->nl ();

  *ps_sh << "// for non-defined forward declared interfaces.";  ps_sh->nl ();

  *ps_sh << "static " << this->interface_name_ << "_ptr tao_duplicate ("
         << this->interface_name_ << "_ptr);";
  ps_sh->nl ();

  *ps_sh << "static void tao_release ("
         << this->interface_name_ << "_ptr);";
  ps_sh->nl ();

  *ps_sh << "static " << this->interface_name_
         << "_ptr tao_nil (void);";  ps_sh->nl ();

  *ps_sh << "static " << this->interface_name_ << "_ptr tao_narrow (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();

  *ps_sh << "CORBA::Object *";
  ps_sh->nl ();
  *ps_sh << "ACE_ENV_ARG_DECL_NOT_USED";

  ps_sh->decr_indent (0);
  ps_sh->nl ();

  *ps_sh << ");";
  ps_sh->nl ();

  *ps_sh << "static CORBA::Object * tao_upcast (void *);";

  ps_sh->reset ();
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "private:";
  ps_sh->incr_indent (0);
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr ptr_;";
  ps_sh->nl ();

  *ps_sh << "// Unimplemented - prevents widening assignment.";
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_var (const TAO_Base_var &rhs);";
  ps_sh->nl ();

  *ps_sh << this->interface_name_
         << "_var &operator= (const TAO_Base_var &rhs);";
  ps_sh->nl ();

  ps_sh->decr_indent (0);
  ps_sh->nl ();

  *ps_sh << "};";
  ps_sh->nl ();

  *ps_sh << "#endif /* end #if !defined */";
  ps_sh->nl ();
  ps_sh->nl ();

  ps_sh->reset ();

  *ps_sh << "#if !defined (_" << name_space
         << "_" << this->interface_name_ << "___OUT_CH_)";
  ps_sh->nl ();

  *ps_sh << "#define _" << name_space
         << "_" << this->interface_name_ << "___OUT_CH_";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "class  " << this->interface_name_ << "_out";  ps_sh->nl ();
  *ps_sh << "{";
  ps_sh->nl ();
  ps_sh->incr_indent (0);

  *ps_sh << "public:";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out (" << this->interface_name_
         << "_ptr &);";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out (" << this->interface_name_
         << "_var &);";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out (const "
         << this->interface_name_ << "_out &);";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out &operator= (const "
         << this->interface_name_ << "_out &);";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out &operator= (const "
         << this->interface_name_ << "_var &);";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_out &operator= ("
         << this->interface_name_ << "_ptr);";  ps_sh->nl ();
  *ps_sh << "operator " << this->interface_name_ << "_ptr &();";  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_ptr &ptr (void);";  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr operator-> (void);";

  ps_sh->reset ();
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "private:";
  ps_sh->incr_indent (0);
  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_ptr &ptr_;";  ps_sh->nl ();

  ps_sh->decr_indent (0);
  ps_sh->nl ();

  *ps_sh << "};\n";

  *ps_sh << "#endif /* end #if !defined */";

  ps_sh->reset ();

  ps_sh->nl ();
  ps_sh->nl ();


  *ps_sh << "// External declarations for undefined interface";
  ps_sh->nl ();
  *ps_sh << "//" << this->interface_name_;
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr";
  ps_sh->nl ();

  *ps_sh << "tao_" << this->interface_name_ << "_duplicate (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr";

  ps_sh->decr_indent (0);
  ps_sh->nl ();
  *ps_sh << ");";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "void";
  ps_sh->nl ();
  *ps_sh << "tao_" << this->interface_name_ << "_release (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();
  *ps_sh << this->interface_name_ << "_ptr";
  ps_sh->decr_indent (0);
  ps_sh->nl ();
  *ps_sh << ");";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr";
  ps_sh->nl ();

  *ps_sh << "tao_" << this->interface_name_ << "_nil (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();
  *ps_sh << "void";
  ps_sh->decr_indent (0);
  ps_sh->nl ();
  *ps_sh << ");";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << this->interface_name_ << "_ptr";
  ps_sh->nl ();

  *ps_sh << "tao_" << this->interface_name_ << "_narrow (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();

  *ps_sh << "CORBA::Object *";
  ps_sh->nl ();

  *ps_sh << "ACE_ENV_ARG_DECL_NOT_USED";

  ps_sh->decr_indent (0);
  ps_sh->nl ();
  *ps_sh << ");";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "CORBA::Object *";
  ps_sh->nl ();
  *ps_sh << "tao_" << this->interface_name_ << "_upcast (";
  ps_sh->incr_indent (0);
  ps_sh->nl ();
  *ps_sh << "void *";
  ps_sh->decr_indent (0);
  ps_sh->nl ();
  *ps_sh << ");";

  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << "// Any operators for interface " << this->interface_name_;
  ps_sh->nl ();

  *ps_sh << "void operator<<= (CORBA::Any &, " << this->interface_name_ << "_ptr);";
  ps_sh->nl ();

  *ps_sh << "CORBA::Boolean operator>>= (const CORBA::Any &, " << this->interface_name_ << " *&);";
  ps_sh->nl ();
  ps_sh->nl ();
  *ps_sh << "#ifndef __ACE_INLINE__";
  ps_sh->nl ();
  ps_sh->nl ();

  *ps_sh << " CORBA::Boolean operator<< (TAO_OutputCDR &, const " << this->interface_name_ << "_ptr );";
  ps_sh->nl ();
  *ps_sh << " CORBA::Boolean operator>> (TAO_InputCDR &, " << this->interface_name_ << "_ptr &);";
  ps_sh->nl ();
  ps_sh->nl ();
  *ps_sh << "#endif /* __ACE_INLINE__ */";
  ps_sh->nl ();

}

void
TAO_PSDL_Interface_Visitor::print_class_for_interface (void)
{
  this->print_for_forward_dcl ();

  ACE_CString name_space = TAO_PSDL_Scope::instance ()->get_name_space ();

  // Get a pointer to PSDL_Stream of the stub header.
  TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();

  *ps_sh << "#if !defined (_" << name_space << "_" << this->interface_name_
         << "_CH_)";  ps_sh->nl ();
  *ps_sh << "#define _" << name_space << this->interface_name_
         << "_CH_";  ps_sh->nl ();

  *ps_sh << "// Forward Classes Declaration.";  ps_sh->nl ();
  *ps_sh << "class _TAO_" << this->interface_name_ << "_Proxy_Impl;";  ps_sh->nl ();
  *ps_sh << "class _TAO_" << this->interface_name_ << "_Remote_Proxy_Impl;";  ps_sh->nl ();
  *ps_sh << "class _TAO_" << this->interface_name_ << "_Proxy_Broker;";  ps_sh->nl ();
  *ps_sh << "class _TAO_" << this->interface_name_ << "_Remote_Proxy_Broker;";  ps_sh->nl ();


  *ps_sh << "class  " << this->interface_name_;
  *ps_sh << ": public virtual CORBA::Object";  ps_sh->nl ();

  *ps_sh << "{";
  ps_sh->nl ();
  ps_sh->incr_indent (0);

  *ps_sh << "public:";  ps_sh->nl ();
  *ps_sh << "#if !defined(__GNUC__) || !defined (ACE_HAS_GNUG_PRE_2_8)"
    ;
  *ps_sh << "typedef " << this->interface_name_ << "_ptr _ptr_type;";  ps_sh->nl ();
  *ps_sh << "typedef " << this->interface_name_ << "_var _var_type;";  ps_sh->nl ();
  *ps_sh << "#endif /* ! __GNUC__ || g++ >= 2.8 */";  ps_sh->nl ();



  *ps_sh << "static int _tao_class_id;";  ps_sh->nl ();

  *ps_sh << "// The static operations.";  ps_sh->nl ();
  *ps_sh << "static " << this->interface_name_
         << "_ptr _duplicate ("
         << this->interface_name_ << "_ptr obj);"
    ;

  *ps_sh << "static " << this->interface_name_ << "_ptr _narrow (";  ps_sh->nl ();
  *ps_sh << "CORBA::Object_ptr obj";  ps_sh->nl ();
  *ps_sh << "ACE_ENV_ARG_DECL_WITH_DEFAULTS";  ps_sh->nl ();
  *ps_sh << ");";  ps_sh->nl ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -