FEDEM Model Database  R8.0
Source code of the FEDEM model database
FFlFEAttributeSpec.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FFL_FE_ATTRIBUTE_SPEC_H
9 #define FFL_FE_ATTRIBUTE_SPEC_H
10 
11 #include <string>
12 #include <set>
13 
14 #define FFL_FE_ATTRIBUTE_SPEC(class) \
15  virtual FFlFEAttributeSpec* getFEAttributeSpec() const \
16  { return FFaSingelton<FFlFEAttributeSpec,class>::instance(); }
17 
18 
20 {
21  class AttribType
22  {
23  public:
24  AttribType() = delete; // No default constructor
25  AttribType(const std::string& aName, bool req, bool multi)
26  : myName(aName), isRequired(req), allowMultiple(multi)
27  { typeID = ++typeIDCounter; }
28 
29  void static init() { typeIDCounter = 0; }
30 
31  std::string myName;
32  bool isRequired;
34  unsigned char typeID;
35 
36  private:
37  static unsigned char typeIDCounter;
38 
39  friend bool operator<(const AttribType& a, const AttribType& b)
40  { return a.myName < b.myName; }
41  };
42 
43 public:
44  void dump() const;
45 
46  bool addLegalAttribute(const std::string& name,
47  bool required = true, bool allowMulti = false);
48 
49  static bool isObsolete(const std::string& name);
50 
51  bool multipleRefsAllowed(const std::string& name) const;
52 
53  const std::string& getAttributeName(unsigned char typeID) const;
54  unsigned char getAttributeTypeID(const std::string& name) const;
55 
56  static void initTypeID() { AttribType::init(); }
57 
58 private:
59  std::set<AttribType> myLegalAttributes;
60 };
61 
62 #endif
Definition: FFlFEAttributeSpec.H:22
bool allowMultiple
Definition: FFlFEAttributeSpec.H:33
static unsigned char typeIDCounter
Definition: FFlFEAttributeSpec.H:37
static void init()
Definition: FFlFEAttributeSpec.H:29
bool isRequired
Definition: FFlFEAttributeSpec.H:32
unsigned char typeID
Definition: FFlFEAttributeSpec.H:34
AttribType(const std::string &aName, bool req, bool multi)
Definition: FFlFEAttributeSpec.H:25
std::string myName
Definition: FFlFEAttributeSpec.H:31
friend bool operator<(const AttribType &a, const AttribType &b)
Definition: FFlFEAttributeSpec.H:39
Definition: FFlFEAttributeSpec.H:20
void dump() const
Definition: FFlFEAttributeSpec.C:91
unsigned char getAttributeTypeID(const std::string &name) const
Definition: FFlFEAttributeSpec.C:81
const std::string & getAttributeName(unsigned char typeID) const
Definition: FFlFEAttributeSpec.C:66
bool addLegalAttribute(const std::string &name, bool required=true, bool allowMulti=false)
Adds a legal attribute to the object.
Definition: FFlFEAttributeSpec.C:23
static void initTypeID()
Definition: FFlFEAttributeSpec.H:56
std::set< AttribType > myLegalAttributes
Definition: FFlFEAttributeSpec.H:59
bool multipleRefsAllowed(const std::string &name) const
Definition: FFlFEAttributeSpec.C:52
static bool isObsolete(const std::string &name)
Definition: FFlFEAttributeSpec.C:34