FEDEM Model Database  R8.0
Source code of the FEDEM model database
FFlPartBase.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_PART_BASE_H
9 #define FFL_PART_BASE_H
10 
11 #include <vector>
12 #include <algorithm>
13 
14 class FFlTypeInfoSpec;
15 class FFaCheckSum;
16 
17 #ifdef FF_NAMESPACE
18 namespace FF_NAMESPACE {
19 #endif
20 
21 
27 {
28 protected:
29 #ifdef FFL_REFCOUNT
30  FFlPartBase(int ID) : myID(ID), nref(0) {}
31  FFlPartBase(const FFlPartBase& other) : myID(other.myID), nref(0) {}
32 #else
33  FFlPartBase(int ID) : myID(ID) {}
34  FFlPartBase(const FFlPartBase&) = default;
35 #endif
36  FFlPartBase& operator=(const FFlPartBase&) = delete;
37 
38 public:
39  virtual ~FFlPartBase() = default;
40 
41  virtual FFlTypeInfoSpec* getTypeInfoSpec() const = 0;
42 
43  int getID() const { return myID; }
44  void setID(int newID) { myID = newID; }
45 
46 #ifdef FFL_REFCOUNT
47  unsigned char getRefCount() const { return nref; }
48  unsigned char ref() { if (nref < 255) ++nref; return nref; }
49  bool unref() { if (nref > 0 && nref < 255) --nref; return nref > 0; }
50 #else
51  unsigned char getRefCount() const { return 1; }
52  unsigned char ref() { return 1; }
53  bool unref() { return true; }
54 #endif
55 
56 protected:
57  void checksum(FFaCheckSum* cs, int csMask = 0) const;
58 
59 private:
60  int myID;
61 #ifdef FFL_REFCOUNT
62  unsigned char nref;
63 #endif
64 };
65 
66 
68 {
69  bool operator()(const FFlPartBase* lhs, const FFlPartBase* rhs) const
70  { return lhs->getID() < rhs->getID(); }
71 
72  bool operator()(const FFlPartBase* lhs, int rhs) const
73  { return lhs->getID() < rhs; }
74 
75  bool operator()(int lhs, const FFlPartBase* rhs) const
76  { return lhs < rhs->getID(); }
77 };
78 
79 
80 template <class T> struct FFlPartFinder
81 {
82  using RefIt = typename std::vector<T*>::const_iterator;
83  static RefIt findObject(const std::vector<T*>& objs, int ID)
84  {
85  std::pair<RefIt,RefIt> p = std::equal_range(objs.begin(), objs.end(),
86  ID, FFlFEPartBaseLess());
87  return p.first == p.second ? objs.end() : p.first;
88  }
89 };
90 
91 #ifdef FF_NAMESPACE
92 } // namespace
93 #endif
94 #endif
Class for holding and calculation of checksum value of objects.
Definition: FFaCheckSum.H:30
Base class for all object types of a FE model.
Definition: FFlPartBase.H:27
unsigned char getRefCount() const
Definition: FFlPartBase.H:51
FFlPartBase & operator=(const FFlPartBase &)=delete
FFlPartBase(const FFlPartBase &)=default
unsigned char ref()
Definition: FFlPartBase.H:52
virtual ~FFlPartBase()=default
virtual FFlTypeInfoSpec * getTypeInfoSpec() const =0
FFlPartBase(int ID)
Definition: FFlPartBase.H:33
void setID(int newID)
Definition: FFlPartBase.H:44
int myID
Definition: FFlPartBase.H:60
int getID() const
Definition: FFlPartBase.H:43
bool unref()
Definition: FFlPartBase.H:53
Definition: FFlTypeInfoSpec.H:22
Definition: FFlPartBase.H:68
bool operator()(const FFlPartBase *lhs, const FFlPartBase *rhs) const
Definition: FFlPartBase.H:69
bool operator()(const FFlPartBase *lhs, int rhs) const
Definition: FFlPartBase.H:72
bool operator()(int lhs, const FFlPartBase *rhs) const
Definition: FFlPartBase.H:75
Definition: FFlPartBase.H:81
typename std::vector< T * >::const_iterator RefIt
Definition: FFlPartBase.H:82
static RefIt findObject(const std::vector< T * > &objs, int ID)
Definition: FFlPartBase.H:83