OMNeT++ NEDXML 6.2.0
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;
48 
49  protected:
50  std::string hFilename;
51  std::string ccFilename;
52  std::ofstream hStream;
53  std::ofstream ccStream;
54  std::string headerGuard;
56 
57  protected:
58  std::string prefixWithNamespace(const std::string& name, const std::string& namespaceName);
59  std::string makeFuncall(const std::string& var, bool isPointer, const std::string& funcTemplate, bool withIndex=false, const std::string& value="");
60  void generateOwnershipOp(const FieldInfo& field, const std::string& var, const std::string& op);
61 
62  void generateClassDecl(const ClassInfo& classInfo, const std::string& exportDef);
63  void generateClassImpl(const ClassInfo& classInfo);
64  void generateStructDecl(const ClassInfo& classInfo, const std::string& exportDef);
65  void generateStructImpl(const ClassInfo& classInfo);
66  void generateCplusplusBlock(std::ofstream& out, const std::string& body);
67  void generateMethodCplusplusBlock(const ClassInfo& classInfo, const std::string& method);
68  void reportUnusedMethodCplusplusBlocks(const ClassInfo& classInfo);
69  void generateDelegationForBaseClassFields(const std::string& code);
70 
71  public:
72  MsgCodeGenerator(ErrorStore *errors) : errors(errors) {}
73  void openFiles(const char *hFile, const char *ccFile);
74  void closeFiles();
75  void deleteFiles();
76  void generateProlog(const std::string& msgFileName, const std::string& firstNamespace, const std::string& exportDef);
77  void generateEpilog();
78  void generateClass(const ClassInfo& classInfo, const std::string& exportDef);
79  void generateStruct(const ClassInfo& classInfo, const std::string& exportDef);
80  void generateToAnyPtr(const ClassInfo& a);
81  void generateFromAnyPtr(const ClassInfo& a, const std::string& exportDef);
82  void generateDescriptorClass(const ClassInfo& a);
83  void generateEnum(const ClassInfo& enumInfo);
84  void generateImport(const std::string& importName);
85  void generateNamespaceBegin(const std::string& namespaceName, bool intoCcFile=true);
86  void generateNamespaceEnd(const std::string& namespaceName, bool intoCcFile=true);
87  void generateTypeAnnouncement(const ClassInfo& classInfo);
88  std::string generatePreComment(ASTNode *nedElement);
89  void generateHeaderCplusplusBlock(const std::string& body);
90  void generateImplCplusplusBlock(const std::string& body);
91 };
92 
93 } // namespace nedxml
94 } // namespace omnetpp
95 
96 
97 #endif
98 
99 
omnetpp::nedxml::MsgCodeGenerator::headerGuard
std::string headerGuard
Definition: msgcodegenerator.h:54
omnetpp::nedxml::MsgTypeTable::Properties
Definition: msgtypetable.h:64
omnetpp::nedxml::MsgTypeTable::ClassInfo
Definition: msgtypetable.h:162
omnetpp::nedxml::MsgCodeGenerator::StringVector
std::vector< std::string > StringVector
Definition: msgcodegenerator.h:43
omnetpp::nedxml::MsgCodeGenerator::hFilename
std::string hFilename
Definition: msgcodegenerator.h:50
omnetpp::nedxml::MsgCodeGenerator
Code generator part of the message compiler.
Definition: msgcodegenerator.h:40
omnetpp::nedxml::MsgCodeGenerator::ccStream
std::ofstream ccStream
Definition: msgcodegenerator.h:53
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:153
omnetpp::nedxml::ASTNode
Definition: astnode.h:87
omnetpp::nedxml::MsgCodeGenerator::MsgCodeGenerator
MsgCodeGenerator(ErrorStore *errors)
Definition: msgcodegenerator.h:72
omnetpp::nedxml::MsgCodeGenerator::errors
ErrorStore * errors
Definition: msgcodegenerator.h:55
errorstore.h
omnetpp::nedxml::MsgCodeGenerator::EnumItem
MsgTypeTable::EnumItem EnumItem
Definition: msgcodegenerator.h:47
omnetpp::nedxml::MsgCodeGenerator::hStream
std::ofstream hStream
Definition: msgcodegenerator.h:52
omnetpp::nedxml::MsgCodeGenerator::ccFilename
std::string ccFilename
Definition: msgcodegenerator.h:51
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