OMNeT++ NEDXML 6.1
Discrete Event Simulation Library
msgcodegenerator.h
Go to the documentation of this file.
1 //==========================================================================
2 // MSGCODEGENERATOR.H - part of
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //==========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 2002-2017 Andras Varga
11  Copyright (C) 2006-2017 OpenSim Ltd.
12 
13  This file is distributed WITHOUT ANY WARRANTY. See the file
14  `license' for details on this and other legal matters.
15 *--------------------------------------------------------------*/
16 
17 #ifndef __OMNETPP_NEDXML_MSGCODEGENERATOR_H
18 #define __OMNETPP_NEDXML_MSGCODEGENERATOR_H
19 
20 #include <iostream>
21 #include <fstream>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <set>
27 
28 #include "errorstore.h"
29 #include "msgelements.h"
30 #include "msgtypetable.h"
31 
32 namespace omnetpp {
33 namespace nedxml {
34 
41 {
42  public:
43  typedef std::vector<std::string> StringVector;
49 
50  protected:
51  std::string hFilename;
52  std::string ccFilename;
53  std::ofstream hStream;
54  std::ofstream ccStream;
55  std::string headerGuard;
57 
58  protected:
59  std::string prefixWithNamespace(const std::string& name, const std::string& namespaceName);
60  std::string makeFuncall(const std::string& var, bool isPointer, const std::string& funcTemplate, bool withIndex=false, const std::string& value="");
61  void generateOwnershipOp(const FieldInfo& field, const std::string& var, const std::string& op);
62 
63  void generateClassDecl(const ClassInfo& classInfo, const std::string& exportDef);
64  void generateClassImpl(const ClassInfo& classInfo);
65  void generateStructDecl(const ClassInfo& classInfo, const std::string& exportDef);
66  void generateStructImpl(const ClassInfo& classInfo);
67  void generateCplusplusBlock(std::ofstream& out, const std::string& body);
68  void generateMethodCplusplusBlock(const ClassInfo& classInfo, const std::string& method);
69  void reportUnusedMethodCplusplusBlocks(const ClassInfo& classInfo);
70  void generateDelegationForBaseClassFields(const std::string& code);
71 
72  public:
73  MsgCodeGenerator(ErrorStore *errors) : errors(errors) {}
74  void openFiles(const char *hFile, const char *ccFile);
75  void closeFiles();
76  void deleteFiles();
77  void generateProlog(const std::string& msgFileName, const std::string& firstNamespace, const std::string& exportDef);
78  void generateEpilog();
79  void generateClass(const ClassInfo& classInfo, const std::string& exportDef);
80  void generateStruct(const ClassInfo& classInfo, const std::string& exportDef);
81  void generateToAnyPtr(const ClassInfo& a);
82  void generateFromAnyPtr(const ClassInfo& a, const std::string& exportDef);
83  void generateDescriptorClass(const ClassInfo& a);
84  void generateEnum(const EnumInfo& enumInfo);
85  void generateImport(const std::string& importName);
86  void generateNamespaceBegin(const std::string& namespaceName, bool intoCcFile=true);
87  void generateNamespaceEnd(const std::string& namespaceName, bool intoCcFile=true);
88  void generateTypeAnnouncement(const ClassInfo& classInfo);
89  std::string generatePreComment(ASTNode *nedElement);
90  void generateHeaderCplusplusBlock(const std::string& body);
91  void generateImplCplusplusBlock(const std::string& body);
92 };
93 
94 } // namespace nedxml
95 } // namespace omnetpp
96 
97 
98 #endif
99 
100 
omnetpp::nedxml::MsgCodeGenerator::headerGuard
std::string headerGuard
Definition: msgcodegenerator.h:55
omnetpp::nedxml::MsgTypeTable::EnumInfo
Definition: msgtypetable.h:232
omnetpp::nedxml::MsgTypeTable::Properties
Definition: msgtypetable.h:64
omnetpp::nedxml::MsgTypeTable::ClassInfo
Definition: msgtypetable.h:153
omnetpp::nedxml::MsgCodeGenerator::StringVector
std::vector< std::string > StringVector
Definition: msgcodegenerator.h:43
omnetpp::nedxml::MsgCodeGenerator::hFilename
std::string hFilename
Definition: msgcodegenerator.h:51
omnetpp::nedxml::MsgCodeGenerator
Code generator part of the message compiler.
Definition: msgcodegenerator.h:40
omnetpp::nedxml::MsgCodeGenerator::ccStream
std::ofstream ccStream
Definition: msgcodegenerator.h:54
omnetpp::nedxml::MsgCodeGenerator::Properties
MsgTypeTable::Properties Properties
Definition: msgcodegenerator.h:44
NEDXML_API
#define NEDXML_API
Definition: nedxmldefs.h:31
omnetpp
Definition: astbuilder.h:25
omnetpp::nedxml::MsgTypeTable::EnumItem
Definition: msgtypetable.h:223
omnetpp::nedxml::ASTNode
Definition: astnode.h:87
omnetpp::nedxml::MsgCodeGenerator::MsgCodeGenerator
MsgCodeGenerator(ErrorStore *errors)
Definition: msgcodegenerator.h:73
omnetpp::nedxml::MsgCodeGenerator::errors
ErrorStore * errors
Definition: msgcodegenerator.h:56
errorstore.h
omnetpp::nedxml::MsgCodeGenerator::EnumItem
MsgTypeTable::EnumItem EnumItem
Definition: msgcodegenerator.h:47
omnetpp::nedxml::MsgCodeGenerator::hStream
std::ofstream hStream
Definition: msgcodegenerator.h:53
omnetpp::nedxml::MsgCodeGenerator::ccFilename
std::string ccFilename
Definition: msgcodegenerator.h:52
omnetpp::nedxml::MsgCodeGenerator::FieldInfo
MsgTypeTable::FieldInfo FieldInfo
Definition: msgcodegenerator.h:45
omnetpp::nedxml::MsgCodeGenerator::ClassInfo
MsgTypeTable::ClassInfo ClassInfo
Definition: msgcodegenerator.h:46
omnetpp::nedxml::ErrorStore
Definition: errorstore.h:37
omnetpp::nedxml::MsgTypeTable::FieldInfo
Definition: msgtypetable.h:76
msgtypetable.h
omnetpp::nedxml::MsgCodeGenerator::EnumInfo
MsgTypeTable::EnumInfo EnumInfo
Definition: msgcodegenerator.h:48