msgcodegenerator.h Source File

NEDXML API: msgcodegenerator.h Source File
NEDXML API
msgcodegenerator.h
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
32namespace omnetpp {
33namespace nedxml {
34
40class NEDXML_API MsgCodeGenerator
41{
42 public:
43 typedef std::vector<std::string> StringVector;
44 typedef MsgTypeTable::Properties Properties;
45 typedef MsgTypeTable::FieldInfo FieldInfo;
46 typedef MsgTypeTable::ClassInfo ClassInfo;
47 typedef MsgTypeTable::EnumItem EnumItem;
48
49 protected:
50 std::string hFilename;
51 std::string ccFilename;
52 std::ofstream hStream;
53 std::ofstream ccStream;
54 std::string headerGuard;
55 ErrorStore *errors;
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
Definition astnode.h:88
Definition errorstore.h:38