Пример #1
0
void UmlTransition::write_it(FileOut & out)
{
    out.indent();
    out << "<transition xmi:type=\"uml:Transition\"";
    out.id(this);

    if (!name().isEmpty() && (name() != "<transition>")) {
        out << " name=\"";
        out.quote(name());
        out << '"';
    }

    out.ref(parent(), "source");
    out.ref(target(), "target");

    if (parent() == target())
        out << " kind=\"" << ((isExternal()) ? "external" : "internal") << '"';

    out << ">\n";
    out.indent(+1);
    write_description_properties(out);

    WrapperStr trig;
    WrapperStr grd;
    WrapperStr effect;

    switch (_lang) {
    case Uml:
        trig = trigger();
        grd = guard();
        effect = activity();
        break;

    case Cpp:
        trig = cppTrigger();
        grd = cppGuard();
        effect = cppActivity();
        break;

    default: // Java
        trig = javaTrigger();
        grd = javaGuard();
        effect = javaActivity();
        break;
    }

    if (! trig.isEmpty()) {
        out.indent();
        out << "<trigger xmi:type=\"uml:Trigger\"";
        out.id_prefix(this, "TRIGGER_");
        out << " name=\"";
        out.quote(trig);
        out << "\"/>\n";
    }

    if (! grd.isEmpty()) {
        out.indent();
        out << "<guard xmi:type=\"uml:Constraint\"";
        out.id_prefix(this, "GUARD_");
        out << ">\n";
        out.indent();
        out << "\t<specification xmi:type=\"uml:OpaqueExpression\"";
        out.id_prefix(this, "GUARD_EXPR_");
        out << ">\n";
        out.indent();
        out << "\t\t<body>";
        out.quote(grd);
        out << "</body>\n";
        out.indent();
        out << "\t</specification>\n";
        out.indent();
        out << "</guard>\n";
    }

    if (! effect.isEmpty()) {
        out.indent();
        out << "<effect xmi:type=\"uml:Activity\"";
        out.id_prefix(this, "EFFECT_");
        out << ">\n";
        out.indent();
        out << "\t<body>";
        out.quote(effect);
        out << "</body>\n";
        out.indent();
        out << "</effect>\n";
    }

    out.indent(-1);
    out.indent();
    out << "</transition>\n";

    unload();
}
Пример #2
0
void UmlTransition::generate(UmlClass * machine, UmlClass * anystate, UmlState * state)
{
    if (_already_managed)
        return;

    Q3CString s = triggerName();

    // group transitions having the same trigger
    const Q3PtrVector<UmlItem> ch = parent()->children();
    unsigned index = ch.findRef(this);
    Q3PtrList<UmlTransition> trs;
    UmlTransition * tr_no_guard = 0;

    if (cppGuard().isEmpty())
        tr_no_guard = this;
    else
        trs.append(this);

    while (++index != ch.count()) {
        if ((ch[index]->kind() == aTransition) &&
            (((UmlTransition *) ch[index])->triggerName() == s)) {
            if (!((UmlTransition *) ch[index])->cppGuard().isEmpty())
                trs.append((UmlTransition *) ch[index]);
            else if (tr_no_guard != 0) {
                UmlCom::trace("Error : several transitions from '" + parent()->name()
                              + "' don't have guard");
                throw 0;
            }
            else
                tr_no_guard = (UmlTransition *) ch[index];

            ((UmlTransition *) ch[index])->_already_managed = TRUE;
        }
    }

    if (tr_no_guard != 0)
        // place it at end
        trs.append(tr_no_guard);

    // made the trigger

    UmlOperation * trg = state->assocClass()->trigger(s, machine, anystate);
    Q3CString body;

    if (s == "create") {
        // manage entry
        if (!state->cppEntryBehavior().isEmpty())
            body = "  _doentry(stm);\n";
    }

    if (!state->cppDoActivity().isEmpty())
        // state do activity before each event except create
        body += "  _do(stm);\n";

    bool completion = (s == "_completion");

    if (!completion && state->isLeaf() && state->hasCompletion())
        // manage completion
        body += "  if (_completion(stm)) return;\n";

    UmlTransition::generate(trs, machine, anystate, state,
                            body, "  ", completion);

    trg->set_CppBody(body);
}
Пример #3
0
bool ts_generator::gen_struct(AST_Structure*, UTL_ScopedName* name,
  const std::vector<AST_Field*>&, AST_Type::SIZE_TYPE, const char*)
{
  if (idl_global->is_dcps_type(name) == 0) {
    // no #pragma DCPS_DATA_TYPE, so nothing to generate
    return true;
  }

  const std::string cxxName = scoped(name);
  const std::string short_name = name->last_component()->get_string();

  static const char* idl_includes[] = {
    "dds/DdsDcpsInfrastructure.idl", "dds/DdsDcpsTopic.idl",
    "dds/DdsDcpsPublication.idl", "dds/DdsDcpsSubscriptionExt.idl",
    "dds/DdsDcpsTypeSupportExt.idl"
  };
  add_includes(idl_includes, BE_GlobalData::STREAM_IDL);

  std::string dc = be_global->header_name_.c_str();
  dc.replace(dc.end() - 6, dc.end() - 2, "C"); // s/Impl.h$/C.h/
  be_global->add_include(dc.c_str());

  static const char* h_includes[] = {
    "dds/DCPS/DataWriterImpl_T.h",
    "dds/DCPS/DataReaderImpl_T.h",
    "dds/DCPS/TypeSupportImpl_T.h"
  };
  add_includes(h_includes, BE_GlobalData::STREAM_H);

  static const char* cpp_includes[] = {
    "dds/DCPS/debug.h", "dds/DCPS/Registered_Data_Types.h",
    "dds/DdsDcpsDomainC.h", "dds/DCPS/Service_Participant.h",
    "dds/DCPS/Qos_Helper.h", "dds/DCPS/PublicationInstance.h",
    "dds/DCPS/PublisherImpl.h", "dds/DCPS/SubscriberImpl.h",
    "dds/DCPS/ReceivedDataElementList.h", "dds/DCPS/RakeResults_T.h",
    "dds/DCPS/BuiltInTopicUtils.h", "dds/DCPS/Util.h",
    "dds/DCPS/ContentFilteredTopicImpl.h", "dds/DCPS/RakeData.h",
    "dds/DCPS/MultiTopicDataReader_T.h"
  };
  add_includes(cpp_includes, BE_GlobalData::STREAM_CPP);

  std::map<std::string, std::string> replacements;
  replacements["SCOPED"] = cxxName;
  replacements["TYPE"] = short_name;
  replacements["EXPORT"] = be_global->export_macro().c_str();
  replacements["SEQ"] = be_global->sequence_suffix().c_str();

  ScopedNamespaceGuard idlGuard(name, be_global->idl_, "module");
  std::string idl = idl_template_;
  replaceAll(idl, replacements);
  be_global->idl_ << idl;

  be_global->header_ <<
    "namespace OpenDDS { namespace DCPS {\n"
    "template <>\n"
    "struct DDSTraits<" << cxxName << "> {\n"
    "  typedef " << cxxName << " MessageType;\n"
    "  typedef " << cxxName << "Seq MessageSequenceType;\n"
    "  typedef " << cxxName << "TypeSupport TypeSupportType;\n"
    "  typedef " << cxxName << "DataWriter DataWriterType;\n"
    "  typedef " << cxxName << "DataReader DataReaderType;\n"
    "  typedef " << module_scope(name) << "OpenDDSGenerated::" << short_name << "_KeyLessThan LessThanType;\n"
    "\n"
    "  inline static const char* type_name () { return \"" << cxxName << "\"; }\n"
    "  inline static bool gen_has_key (const MessageType& x) { return ::OpenDDS::DCPS::gen_has_key(x); }\n"
    "\n"
    "  inline static bool gen_is_bounded_size (const MessageType& x) { return ::OpenDDS::DCPS::gen_is_bounded_size(x); }\n"
    "  inline static size_t gen_max_marshaled_size(const MessageType& x, bool align) { return ::OpenDDS::DCPS::gen_max_marshaled_size(x, align); }\n"
    "  inline static void gen_find_size(const MessageType& arr, size_t& size, size_t& padding) { ::OpenDDS::DCPS::gen_find_size(arr, size, padding); }\n"
    "\n"
    "  inline static bool gen_is_bounded_size (const OpenDDS::DCPS::KeyOnly<const MessageType>& x) { return ::OpenDDS::DCPS::gen_is_bounded_size(x); }\n"
    "  inline static size_t gen_max_marshaled_size(const OpenDDS::DCPS::KeyOnly<const MessageType>& x, bool align) { return ::OpenDDS::DCPS::gen_max_marshaled_size(x, align); }\n"
    "  inline static void gen_find_size(const OpenDDS::DCPS::KeyOnly<const MessageType>& arr, size_t& size, size_t& padding) { ::OpenDDS::DCPS::gen_find_size(arr, size, padding); }\n"
    "};\n}  }\n\n";

  {
    ScopedNamespaceGuard hGuard(name, be_global->header_);
    be_global->header_ <<
      "  typedef OpenDDS::DCPS::DataWriterImpl_T<" << cxxName << "> " << short_name << "DataWriterImpl;\n"
      "  typedef OpenDDS::DCPS::DataReaderImpl_T<" << cxxName << "> " << short_name << "DataReaderImpl;\n"
      "  typedef OpenDDS::DCPS::TypeSupportImpl_T<" << cxxName << "> " << short_name << "TypeSupportImpl;\n";
  }

  ScopedNamespaceGuard cppGuard(name, be_global->impl_);

  if (be_global->face_ts()) {
    face_ts_generator::generate(name);
  }

  return true;
}