Scippy

SoPlex

Sequential object-oriented simPlex

datakey.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file datakey.h
17  * @brief Entry identifier class for items of a DataSet.
18  */
19 #ifndef _DATAKEY_H_
20 #define _DATAKEY_H_
21 
22 #include <assert.h>
23 
24 namespace soplex
25 {
26 /**@brief Entry identifier class for items of a DataSet.
27  @ingroup Elementary
28 
29  Every item in a DataSet is assigned a DataKey by which it can be
30  accessed (using DataSet::operator[]()). A DataKey consists of an integer
31  member #idx, which is a positive number for any valid DataKey. No
32  #idx of an element in a DataSet may exceed the sets max().
33  This property may be used to build arrays with additional information to
34  the elements of a DataSet.
35 
36  In addition, #DataKey%s provide a member #info which can be used to store
37  further information.
38 
39  Each DataKey is unique for one DataSet but different DataSets may (and
40  generally will) manage the same #DataKey%s. When an element is removed from
41  a DataSet its DataKey may (and generally will) be reused for other
42  elements added to the DataSet later on.
43 
44  @todo data members should be private.
45 */
46 class DataKey
47 {
48 public:
49 
50  //-------------------------------------
51  /**@name Data */
52  //@{
53  /* This was originally implemented as bitfield "signed int info: 2; signed int idx: (8 * sizeof(int) - 2);",
54  however, this seems to trigger a bug with old versions of GCC/glibc on 32bit machines. */
55  int info; ///< user information to store values -1, 0, +1
56  int idx; ///< (locally) unique key index
57  //@}
58 
59 public:
60 
61  //-------------------------------------
62  /**@name Constructors / destructors */
63  //@{
64  /// Default constructor. Constructs an invalid DataKey.
66  : info(0), idx(-1)
67  {}
68  // Full constructor
69  DataKey(int p_info, int p_idx)
70  : info(p_info)
71  , idx(p_idx)
72  {
73  assert(p_info <= 1 && p_info >= -1);
74  }
75  /// Assignment operator.
76  DataKey& operator=(const DataKey& rhs)
77  {
78  if(this != &rhs)
79  {
80  info = rhs.info;
81  idx = rhs.idx;
82  }
83 
84  return *this;
85  }
86  /// Copy constructor.
87  DataKey(const DataKey& old)
88  : info(old.info)
89  , idx(old.idx)
90  {}
91  //@}
92 
93  //-------------------------------------
94  /**@name Access / modification */
95  //@{
96  /// gets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
97  inline int getIdx() const
98  {
99  return idx;
100  }
101  /// sets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
102  inline void setIdx(int p_idx)
103  {
104  idx = p_idx;
105  }
106  /// returns TRUE, iff the DataKey is valid.
107  inline bool isValid() const
108  {
109  return idx >= 0;
110  }
111  /// makes the DataKey invalid and clears the \ref soplex::DataKey::info "info" field.
112  inline void inValidate()
113  {
114  idx = -1;
115  info = 0;
116  }
117  //@}
118 
119 };
120 
121 } // namespace soplex
122 #endif // _DATAKEY_H_
Entry identifier class for items of a DataSet.Every item in a DataSet is assigned a DataKey by which ...
Definition: datakey.h:46
void inValidate()
makes the DataKey invalid and clears the info field.
Definition: datakey.h:112
int getIdx() const
gets the index number (idx) of the DataKey.
Definition: datakey.h:97
int info
user information to store values -1, 0, +1
Definition: datakey.h:55
DataKey(int p_info, int p_idx)
Definition: datakey.h:69
DataKey & operator=(const DataKey &rhs)
Assignment operator.
Definition: datakey.h:76
Everything should be within this namespace.
DataKey()
Default constructor. Constructs an invalid DataKey.
Definition: datakey.h:65
void setIdx(int p_idx)
sets the index number (idx) of the DataKey.
Definition: datakey.h:102
DataKey(const DataKey &old)
Copy constructor.
Definition: datakey.h:87
int idx
(locally) unique key index
Definition: datakey.h:56
bool isValid() const
returns TRUE, iff the DataKey is valid.
Definition: datakey.h:107