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-2023 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file datakey.h
26  * @brief Entry identifier class for items of a DataSet.
27  */
28 #ifndef _DATAKEY_H_
29 #define _DATAKEY_H_
30 
31 #include <assert.h>
32 
33 namespace soplex
34 {
35 /**@brief Entry identifier class for items of a DataSet.
36  @ingroup Elementary
37 
38  Every item in a DataSet is assigned a DataKey by which it can be
39  accessed (using DataSet::operator[]()). A DataKey consists of an integer
40  member #idx, which is a positive number for any valid DataKey. No
41  #idx of an element in a DataSet may exceed the sets max().
42  This property may be used to build arrays with additional information to
43  the elements of a DataSet.
44 
45  In addition, #DataKey%s provide a member #info which can be used to store
46  further information.
47 
48  Each DataKey is unique for one DataSet but different DataSets may (and
49  generally will) manage the same #DataKey%s. When an element is removed from
50  a DataSet its DataKey may (and generally will) be reused for other
51  elements added to the DataSet later on.
52 
53  @todo data members should be private.
54 */
55 class DataKey
56 {
57 public:
58 
59  //-------------------------------------
60  /**@name Data */
61  ///@{
62  /* This was originally implemented as bitfield "signed int info: 2; signed int idx: (8 * sizeof(int) - 2);",
63  however, this seems to trigger a bug with old versions of GCC/glibc on 32bit machines. */
64  int info; ///< user information to store values -1, 0, +1
65  int idx; ///< (locally) unique key index
66  ///@}
67 
68 public:
69 
70  //-------------------------------------
71  /**@name Constructors / destructors */
72  ///@{
73  /// Default constructor. Constructs an invalid DataKey.
75  : info(0), idx(-1)
76  {}
77  // Full constructor
78  DataKey(int p_info, int p_idx)
79  : info(p_info)
80  , idx(p_idx)
81  {
82  assert(p_info <= 1 && p_info >= -1);
83  }
84 
85  ///@}
86 
87  //-------------------------------------
88  /**@name Access / modification */
89  ///@{
90  /// gets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
91  inline int getIdx() const
92  {
93  return idx;
94  }
95  /// sets the index number (\ref soplex::DataKey::idx "idx") of the DataKey.
96  inline void setIdx(int p_idx)
97  {
98  idx = p_idx;
99  }
100  /// returns TRUE, iff the DataKey is valid.
101  inline bool isValid() const
102  {
103  return idx >= 0;
104  }
105  /// makes the DataKey invalid and clears the \ref soplex::DataKey::info "info" field.
106  inline void inValidate()
107  {
108  idx = -1;
109  info = 0;
110  }
111  ///@}
112 
113 };
114 
115 } // namespace soplex
116 #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:55
void inValidate()
makes the DataKey invalid and clears the info field.
Definition: datakey.h:106
int getIdx() const
gets the index number (idx) of the DataKey.
Definition: datakey.h:91
int info
user information to store values -1, 0, +1
Definition: datakey.h:64
DataKey(int p_info, int p_idx)
Definition: datakey.h:78
Everything should be within this namespace.
DataKey()
Default constructor. Constructs an invalid DataKey.
Definition: datakey.h:74
void setIdx(int p_idx)
sets the index number (idx) of the DataKey.
Definition: datakey.h:96
int idx
(locally) unique key index
Definition: datakey.h:65
bool isValid() const
returns TRUE, iff the DataKey is valid.
Definition: datakey.h:101