| eRPC Generator (erpcgen) Rev. 1.8.1 NXP Semiconductors

- Main Page
- Classes
- Files

- File List

UnionType.h
1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__UNIONTYPE_H_
11 #define _EMBEDDED_RPC__UNIONTYPE_H_
12
13 #include "DataType.h"
14 #include "StructType.h"
15 #include "UnionCase.h"
16
17 #include <map>
18
20 // Classes
22
23 namespace erpcgen {
24
28 class UnionType : public DataType
29 {
30 public:
31 typedef std::vector<UnionCase *> case_vector_t;
42 UnionType(const std::string &name, const std::string &discriminatorName)
43 : DataType(name, kUnionType, kUnionTypeSymbol)
44 , m_discriminator(discriminatorName)
45 , m_members("(union)")
46 , m_parentStruct(nullptr)
47 {
48 }
49
59 UnionType(const Token &tok, const std::string &discriminatorName)
60 : DataType(tok, kUnionType, kUnionTypeSymbol)
61 , m_discriminator(discriminatorName)
62 , m_members("(union)")
63 , m_parentStruct(nullptr)
64 {
65 }
66
70 StructType *getParentStruct() { return m_parentStruct; }
71
75 void setParentStruct(StructType *parent) { m_parentStruct = parent; }
76
82 void addCase(UnionCase *unionCase);
83
97 virtual std::string getDescription() const;
98
104 virtual bool isUnion() const { return true; }
105
112 bool isNonEncapsulatedUnion() const { return m_discriminator.compare("") == 0; }
113
119 case_vector_t &getCases() { return m_unionCases; }
120
126 case_vector_t getUniqueCases();
127
134 bool addUnionMemberDeclaration(const std::string &name, DataType *dataType);
135
141 StructType &getUnionMembers() { return m_members; }
142
150 StructMember *getUnionMemberDeclaration(const std::string &name);
151
157 std::string getDiscriminatorName() { return m_discriminator; }
158
162 void printUnionMembers();
163
172 bool declarationExists(const std::string &name);
173
174 private:
175 std::string m_discriminator;
176 case_vector_t m_unionCases;
177 StructType m_members;
178 StructType *m_parentStruct;
189 bool casesAreTheSame(UnionCase *a, UnionCase *b);
190 };
191
192 } // namespace erpcgen
193
194 #endif // _EMBEDDED_RPC__UNIONTYPE_H_
erpcgen::UnionType::getUniqueCases
case_vector_t getUniqueCases()
This function returns unique union cases vector.
Definition: Type.cpp:591
erpcgen::UnionType::isUnion
virtual bool isUnion() const
This function return "true" value for identify union type.
Definition: UnionType.h:104
erpcgen::StructMember
Member of a struct.
Definition: StructMember.h:38
erpcgen::UnionType::printUnionMembers
void printUnionMembers()
This function prints information about union members.
Definition: Type.cpp:666
erpcgen::UnionType::case_vector_t
std::vector< UnionCase * > case_vector_t
Definition: UnionType.h:31
erpcgen::UnionType::getUnionMemberDeclaration
StructMember * getUnionMemberDeclaration(const std::string &name)
This function returns union member declaration.
Definition: Type.cpp:654
erpcgen::UnionCase
Discriminated union case type.
Definition: UnionCase.h:26
erpcgen::StructType
Structure data type.
Definition: StructType.h:29
erpcgen::UnionType::setParentStruct
void setParentStruct(StructType *parent)
Sets the struct owning this union.
Definition: UnionType.h:75
erpcgen::UnionType::addCase
void addCase(UnionCase *unionCase)
This function will add union case to current union.
Definition: Type.cpp:575
erpcgen::UnionType::getDescription
virtual std::string getDescription() const
This function returns description about the union.
Definition: Type.cpp:581
erpcgen::UnionType::getUnionMembers
StructType & getUnionMembers()
This function returns struct of union members.
Definition: UnionType.h:141
erpcgen::UnionType::UnionType
UnionType(const Token &tok, const std::string &discriminatorName)
Constructor.
Definition: UnionType.h:59
erpcgen::UnionType::getDiscriminatorName
std::string getDiscriminatorName()
This function returns union discriminator name.
Definition: UnionType.h:157
erpcgen::DataType
Base class for data types.
Definition: DataType.h:26
erpcgen::Token
Encapsulates all information about a token.
Definition: Token.h:60
erpcgen::UnionType::UnionType
UnionType(const std::string &name, const std::string &discriminatorName)
Constructor.
Definition: UnionType.h:42
erpcgen::UnionType::isNonEncapsulatedUnion
bool isNonEncapsulatedUnion() const
This function return "true" value for identify non-encapsulated discriminated union type...
Definition: UnionType.h:112
erpcgen::UnionType
Discriminated union data type.
Definition: UnionType.h:28
erpcgen::UnionType::getParentStruct
StructType * getParentStruct()
Returns the struct owning this union.
Definition: UnionType.h:70
erpcgen::UnionType::addUnionMemberDeclaration
bool addUnionMemberDeclaration(const std::string &name, DataType *dataType)
This function adds unique union member declaration.
Definition: Type.cpp:631
erpcgen::UnionType::getCases
case_vector_t & getCases()
This function returns union cases vector.
Definition: UnionType.h:119
erpcgen
Definition: AstNode.h:26
erpcgen::UnionType::declarationExists
bool declarationExists(const std::string &name)
This function is looking for member declaration.
Definition: Type.cpp:642