delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
Variable.cpp
1
6
#include "delpi/symbolic/Variable.h"
7
8
#include <atomic>
9
#include <limits>
10
#include <ostream>
11
#include <string>
12
#include <utility>
13
#include <vector>
14
15
#include "delpi/util/error.h"
16
17
namespace
delpi
{
18
std::vector<std::string>
Variable::names_
{{
"dummy"
}};
19
const
Variable::Id
Variable::dummy_id
{std::numeric_limits<Id>::max()};
20
21
Variable::Id
Variable::GetNextId
() {
22
static
std::atomic<Id> next_id{0};
23
const
std::size_t counter = next_id.fetch_add(1);
24
return
counter;
25
}
26
Variable::Variable
(
const
Id
id
) :
id_
{id} {
27
DELPI_ASSERT(
id
<
names_
.size(),
"The id is out of bounds. Make sure the variable had been created before."
);
28
}
29
30
Variable::Variable
(std::string name) :
id_
{
GetNextId
()} {
31
DELPI_ASSERT(
id_
< std::numeric_limits<Id>::max(),
"The ID of the variable has reached the maximum value."
);
32
names_
.push_back(std::move(name));
33
DELPI_ASSERT(
names_
.size() ==
id_
+ 2u,
"The size of the names vector is not equal to the ID + dummy string."
);
34
}
35
36
std::ostream &operator<<(std::ostream &os,
const
Variable
&var) {
return
os << var.name(); }
37
38
}
// namespace delpi
delpi::Variable
Real symbolic variable.
Definition
Variable.h:20
delpi::Variable::names_
static std::vector< std::string > names_
Names of all existing variables.
Definition
Variable.h:67
delpi::Variable::id_
Id id_
Unique identifier.
Definition
Variable.h:74
delpi::Variable::dummy_id
static const Id dummy_id
ID of the dummy variable.
Definition
Variable.h:24
delpi::Variable::Variable
Variable()
Construct a new dummy variable object.
Definition
Variable.h:34
delpi::Variable::GetNextId
static Id GetNextId()
Get the next unique identifier for a variable.
Definition
Variable.cpp:21
delpi
Global namespace for the delpi library.
delpi
symbolic
Variable.cpp
Generated by
1.17.0