eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
UnionCase.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__UNIONCASE_H_
37 #define _EMBEDDED_RPC__UNIONCASE_H_
38 #include <map>
39 #include <utility>
40 
42 // Classes
44 
45 namespace erpcgen {
46 
47 class UnionType;
48 
52 class UnionCase : public Symbol
53 {
54 public:
64  UnionCase(const std::string &caseName, int32_t caseValue)
65  : Symbol(kUnionCaseMemberSymbol, caseName)
66  , m_caseName(caseName)
67  , m_caseValue(caseValue)
68  , m_containingUnion(nullptr)
69  {
70  }
71 
80  UnionCase(int32_t caseValue)
81  : Symbol(kUnionCaseMemberSymbol)
82  , m_caseName("")
83  , m_caseValue(caseValue)
84  , m_containingUnion(nullptr)
85  {
86  }
87 
96  UnionCase(const std::string &caseName)
97  : Symbol(kUnionCaseMemberSymbol)
98  , m_caseName(caseName)
99  , m_caseValue(-1)
100  , m_containingUnion(nullptr)
101  {
102  }
103 
109  void setUnionReferencePointer(UnionType *unionType) { m_containingUnion = unionType; }
110 
116  int32_t getCaseValue() const { return m_caseValue; }
117 
123  std::string getCaseName() { return m_caseName; }
124 
130  std::vector<std::string> getMemberDeclarationNames() const { return m_memberDeclarationNames; }
131 
137  void addCaseMemberName(const std::string &name) { m_memberDeclarationNames.push_back(name); };
138 
142  void printUnionMembers();
143 
150  bool caseMemberIsVoid() const;
151 
157  virtual std::string getDescription() const;
158 
166  StructMember *getUnionMemberDeclaration(const std::string &name);
167 
168 private:
169  std::string m_caseName;
170  int32_t m_caseValue;
171  std::vector<std::string> m_memberDeclarationNames;
172  UnionType *m_containingUnion;
173 };
174 
175 } // namespace erpcgen
176 
177 #endif // _EMBEDDED_RPC__UNIONCASE_H_
UnionCase(int32_t caseValue)
Constructor.
Definition: UnionCase.h:80
UnionCase(const std::string &caseName)
Constructor.
Definition: UnionCase.h:96
Member of a struct.
Definition: StructMember.h:63
Discriminated union case type.
Definition: UnionCase.h:52
std::string getCaseName()
This function returns union case name.
Definition: UnionCase.h:123
Base class for all named declarations in the IDL.
Definition: Symbol.h:53
StructMember * getUnionMemberDeclaration(const std::string &name)
This function returns union member declaration.
Definition: Type.cpp:595
void setUnionReferencePointer(UnionType *unionType)
This function set reference to union type.
Definition: UnionCase.h:109
std::vector< std::string > getMemberDeclarationNames() const
This function returns vector of member declarations.
Definition: UnionCase.h:130
int32_t getCaseValue() const
This function returns union case value.
Definition: UnionCase.h:116
void addCaseMemberName(const std::string &name)
This function adds case member name.
Definition: UnionCase.h:137
UnionCase(const std::string &caseName, int32_t caseValue)
Constructor.
Definition: UnionCase.h:64
Discriminated union data type.
Definition: UnionType.h:53
void printUnionMembers()
This function prints debug information about union case members.
virtual std::string getDescription() const
This function returns description about case members.
Definition: Type.cpp:572
bool caseMemberIsVoid() const
This function returns information if case is void type.
Definition: Type.cpp:563
Definition: AstNode.h:51