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-2022 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 
76  ///@}
77 
78  //-------------------------------------
79  /**@name Access / modification */
80  ///@{
81  /// gets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
82  inline int getIdx() const
83  {
84  return idx;
85  }
86  /// sets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
87  inline void setIdx(int p_idx)
88  {
89  idx = p_idx;
90  }
91  /// returns TRUE, iff the DataKey is valid.
92  inline bool isValid() const
93  {
94  return idx >= 0;
95  }
96  /// makes the DataKey invalid and clears the \ref soplex::DataKey::info "info" field.
97  inline void inValidate()
98  {
99  idx = -1;
100  info = 0;
101  }
102  ///@}
103 
104 };
105 
106 } // namespace soplex
107 #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:97
int getIdx() const
gets the index number (idx) of the DataKey.
Definition: datakey.h:82
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
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:87
int idx
(locally) unique key index
Definition: datakey.h:56
bool isValid() const
returns TRUE, iff the DataKey is valid.
Definition: datakey.h:92