Skip to content

Commit

Permalink
[clib] Rename SharedCabinet to Cabinet
Browse files Browse the repository at this point in the history
Revert to original name after SharedCabinet was introduced in #1448 and
the original Cabinet was subsequently removed.
  • Loading branch information
ischoegl authored and speth committed Aug 19, 2024
1 parent 5009d1f commit c16cbe6
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 56 deletions.
52 changes: 26 additions & 26 deletions src/clib/Cabinet.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@
namespace Cantera {

/**
* Template for classes to hold pointers to objects. The SharedCabinet<M> class
* Template for classes to hold pointers to objects. The Cabinet<M> class
* maintains a list of pointers to objects of class M (or of subclasses of M). These
* classes are used by the 'clib' interface library functions that provide access to
* %Cantera C++ objects from outside C++. To refer to an existing object, the library
* functions take an integer argument that specifies the location in the pointer list
* maintained by the appropriate SharedCabinet<M> instance. The pointer is retrieved
* maintained by the appropriate Cabinet<M> instance. The pointer is retrieved
* from the list by the interface function, the desired method is invoked, and the
* result returned to the non-C++ calling procedure. By storing the pointers in a
* SharedCabinet, there is no need to encode them in a string or integer and pass
* Cabinet, there is no need to encode them in a string or integer and pass
* them out to the non-C++ calling routine, as some other interfacing schemes do.
*
* The SharedCabinet<M> class can be used to store pointers to arbitrary objects. In
* The Cabinet<M> class can be used to store pointers to arbitrary objects. In
* most cases, class M is a base class with virtual methods, and the base class versions
* of the methods throw CanteraError exceptions. The subclasses overload these methods
* to implement the desired functionality. Class SharedCabinet<M> stores only the
* to implement the desired functionality. Class Cabinet<M> stores only the
* base-class pointers, but since the methods are virtual, the method of the appropriate
* subclass will be invoked.
*
* As the SharedCabinet<M> class uses smart pointers, it is set up to allow deleting
* As the Cabinet<M> class uses smart pointers, it is set up to allow deleting
* objects in an inherently safe manner. Method 'del' does the following. If called
* with n >= 0, it dereferences the object. The original object is only destroyed if the
* reference is not shared by other objects. In this way, if it is deleted again
* inadvertently nothing happens, and if an attempt is made to reference the object by
* its index number, a standard exception is thrown.
*
* The SharedCabinet<M> class is implemented as a singleton. The constructor is never
* explicitly called; instead, static function SharedCabinet<M>::SharedCabinet() is
* The Cabinet<M> class is implemented as a singleton. The constructor is never
* explicitly called; instead, static function Cabinet<M>::Cabinet() is
* called to obtain a pointer to the instance. This function calls the constructor on
* the first call and stores the pointer to this instance. Subsequent calls simply
* return the already-created pointer.
*/
template<class M>
class SharedCabinet
class Cabinet
{
public:
typedef vector<shared_ptr<M>>& dataRef;
Expand All @@ -57,7 +57,7 @@ class SharedCabinet
/**
* Constructor.
*/
SharedCabinet() {}
Cabinet() {}

/**
* Add a new object. The index of the object is returned.
Expand Down Expand Up @@ -113,7 +113,7 @@ class SharedCabinet
try {
return add(*data[n]); // do not copy parent to avoid ambiguous data
} catch (std::exception& err) {
throw CanteraError("SharedCabinet::newCopy", err.what());
throw CanteraError("Cabinet::newCopy", err.what());
}
}

Expand All @@ -125,7 +125,7 @@ class SharedCabinet
if (n >= 0 && n < len(data)) {
lookupRef lookup = getLookup();
if (!lookup.count(data[n].get())) {
throw CanteraError("SharedCabinet::del",
throw CanteraError("Cabinet::del",
"Lookup table does not contain reference to object.");
}
if (lookup[data[n].get()].size() == 1) {
Expand All @@ -137,7 +137,7 @@ class SharedCabinet
}
data[n].reset();
} else {
throw CanteraError("SharedCabinet::del",
throw CanteraError("Cabinet::del",
"Attempt made to delete a non-existing object.");
}
}
Expand All @@ -148,7 +148,7 @@ class SharedCabinet
static int parent(int n) {
auto& parents = getParents();
if (n < 0 || n >= len(parents)) {
throw CanteraError("SharedCabinet::parent", "Index {} out of range.", n);
throw CanteraError("Cabinet::parent", "Index {} out of range.", n);
}
return parents[n];
}
Expand All @@ -159,10 +159,10 @@ class SharedCabinet
static shared_ptr<M>& at(int n) {
dataRef data = getData();
if (n < 0 || n >= len(data)) {
throw CanteraError("SharedCabinet::at", "Index {} out of range.", n);
throw CanteraError("Cabinet::at", "Index {} out of range.", n);
}
if (!data[n]) {
throw CanteraError("SharedCabinet::at",
throw CanteraError("Cabinet::at",
"Object with index {} has been deleted.", n);
}
return data[n];
Expand All @@ -177,12 +177,12 @@ class SharedCabinet
if (obj) {
return obj;
}
throw CanteraError("SharedCabinet::as", "Item is not of the correct type.");
throw CanteraError("Cabinet::as", "Item is not of the correct type.");
}

/**
* Return the index in the SharedCabinet to the specified object, or -1 if the
* object is not in the SharedCabinet. If multiple indices reference the same
* Return the index in the Cabinet to the specified object, or -1 if the
* object is not in the Cabinet. If multiple indices reference the same
* object, the index of the last one added is returned.
*/
static int index(const M& obj, int parent=-1) {
Expand All @@ -203,44 +203,44 @@ class SharedCabinet
private:
/**
* Static function that returns a pointer to the data member of
* the singleton SharedCabinet<M> instance. All member functions should
* the singleton Cabinet<M> instance. All member functions should
* access the data through this function.
*/
static dataRef getData() {
if (s_storage == nullptr) {
s_storage = new SharedCabinet<M>();
s_storage = new Cabinet<M>();
}
return s_storage->m_table;
}

/**
* Static function that returns a pointer to the list of parent object handles of
* the singleton SharedCabinet<M> instance. All member functions should
* the singleton Cabinet<M> instance. All member functions should
* access the data through this function.
*/
static vector<int>& getParents() {
if (s_storage == nullptr) {
s_storage = new SharedCabinet<M>();
s_storage = new Cabinet<M>();
}
return s_storage->m_parents;
}

/**
* Static function that returns a pointer to the reverse lookup table of
* the singleton SharedCabinet<M> instance. All member functions should
* the singleton Cabinet<M> instance. All member functions should
* access the lookup table through this function.
*/
static lookupRef getLookup() {
if (s_storage == nullptr) {
s_storage = new SharedCabinet<M>();
s_storage = new Cabinet<M>();
}
return s_storage->m_lookup;
}

/**
* Pointer to the single instance of this class.
*/
static SharedCabinet<M>* s_storage;
static Cabinet<M>* s_storage;

/**
* Reverse lookup table for the single instance of this class.
Expand Down
8 changes: 4 additions & 4 deletions src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

using namespace Cantera;

typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef SharedCabinet<Kinetics> KineticsCabinet;
typedef SharedCabinet<Transport> TransportCabinet;
typedef SharedCabinet<Solution> SolutionCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Transport> TransportCabinet;
typedef Cabinet<Solution> SolutionCabinet;

template<> ThermoCabinet* ThermoCabinet::s_storage = 0;
template<> KineticsCabinet* KineticsCabinet::s_storage = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/clib/ctfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

using namespace Cantera;

typedef SharedCabinet<Func1> FuncCabinet;
// Assign storage to the SharedCabinet<Func1> static member
typedef Cabinet<Func1> FuncCabinet;
// Assign storage to the Cabinet<Func1> static member
template<> FuncCabinet* FuncCabinet::s_storage = 0;

extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions src/clib/ctmultiphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

using namespace Cantera;

typedef SharedCabinet<MultiPhase> mixCabinet;
typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<MultiPhase> mixCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;

template<> mixCabinet* mixCabinet::s_storage = 0;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp
Expand Down
12 changes: 6 additions & 6 deletions src/clib/ctonedim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
using namespace std;
using namespace Cantera;

typedef SharedCabinet<Sim1D> SimCabinet;
typedef SharedCabinet<Domain1D> DomainCabinet;
typedef Cabinet<Sim1D> SimCabinet;
typedef Cabinet<Domain1D> DomainCabinet;
template<> SimCabinet* SimCabinet::s_storage = 0;
template<> DomainCabinet* DomainCabinet::s_storage = 0;

typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef SharedCabinet<Kinetics> KineticsCabinet;
typedef SharedCabinet<Transport> TransportCabinet;
typedef SharedCabinet<Solution> SolutionCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Transport> TransportCabinet;
typedef Cabinet<Solution> SolutionCabinet;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp
template<> KineticsCabinet* KineticsCabinet::s_storage; // defined in ct.cpp
template<> TransportCabinet* TransportCabinet::s_storage; // defined in ct.cpp
Expand Down
18 changes: 9 additions & 9 deletions src/clib/ctreactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

using namespace Cantera;

typedef SharedCabinet<ReactorBase> ReactorCabinet;
typedef SharedCabinet<ReactorNet> NetworkCabinet;
typedef SharedCabinet<FlowDevice> FlowDeviceCabinet;
typedef SharedCabinet<WallBase> WallCabinet;
typedef SharedCabinet<Func1> FuncCabinet;
typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef SharedCabinet<Kinetics> KineticsCabinet;
typedef SharedCabinet<Solution> SolutionCabinet;
typedef SharedCabinet<ReactorSurface> ReactorSurfaceCabinet;
typedef Cabinet<ReactorBase> ReactorCabinet;
typedef Cabinet<ReactorNet> NetworkCabinet;
typedef Cabinet<FlowDevice> FlowDeviceCabinet;
typedef Cabinet<WallBase> WallCabinet;
typedef Cabinet<Func1> FuncCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Solution> SolutionCabinet;
typedef Cabinet<ReactorSurface> ReactorSurfaceCabinet;

template<> ReactorCabinet* ReactorCabinet::s_storage = 0;
template<> NetworkCabinet* NetworkCabinet::s_storage = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/clib/ctrpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
using namespace Cantera;
using namespace std;

typedef SharedCabinet<ReactionPathBuilder> BuilderCabinet;
typedef SharedCabinet<ReactionPathDiagram> DiagramCabinet;
typedef Cabinet<ReactionPathBuilder> BuilderCabinet;
typedef Cabinet<ReactionPathDiagram> DiagramCabinet;
template<> DiagramCabinet* DiagramCabinet::s_storage = 0;
template<> BuilderCabinet* BuilderCabinet::s_storage = 0;

typedef SharedCabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
template<> KineticsCabinet* KineticsCabinet::s_storage; // defined in ct.cpp

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/clib/ctsurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using namespace Cantera;

typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp


Expand Down
6 changes: 3 additions & 3 deletions src/fortran/fct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

using namespace Cantera;

typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef SharedCabinet<Kinetics> KineticsCabinet;
typedef SharedCabinet<Transport> TransportCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Transport> TransportCabinet;

typedef integer status_t;

Expand Down

0 comments on commit c16cbe6

Please sign in to comment.