.TH "persistent_table" 7rheolef "Version 7.2" "rheolef" \" -*- nroff -*- .ad l .nh .SH NAME persistent_table \- persistent data base (rheolef-7\&.2) .PP .SH "DESCRIPTION" .PP Here is a convenient way to implement a persistent data base of big object that are long to initialize and then used only in a read-only mode, via accessors, no modifiers\&. Examples of such objects in scientific computing are are finite element meshes (see \fBgeo(2)\fP), that are long to load from file and requires large memory, or high-order polynomial basis (see \fBbasis(2)\fP), that are long to initialize (e\&.g\&. Vandermonde matrix inversion)\&. When such objects are created independently in different parts of a code, both memory size and computation time could be save by reusing them when these objects was already created\&. .PP The aim of the \fBpersistent_table\fP class is to automate the implementation of a persistent data base for a generic object, that could be e\&.g\&. a finite element mesh or a polynomial basis\&. It requires very few modification of a pre-existing object\&. The implementation of the \fBpersistent_table\fP class bases on those of \fBsmart_pointer(7)\fP class for handling reference counting\&. When shared object in the data base are not modifiable, the idea is to use the \fCsmart_pointer_nocopy\fP class\&. Otherwise, when the object has to be modified, the name of the object, that is used as a key in an hashtable, should also be modified, in order to address the new modified object\&. Here is a small minimalist example of the class\&. .SH "EXAMPLE" .PP .PP .nf struct A_rep { public: A_rep (const string& name1) : _name(name1) { /* long init */ } ~A_rep(); string name() const { return _name; } static A_rep* make_ptr (const string& name) { return new A_rep (name); } // data: protected: string _name; }; struct A : public smart_pointer_nocopy, public persistent_table { public: using rep = A_rep; using base = smart_pointer_nocopy; A (const string& name = ""); string name() const { return base::data()\&.name(); } }; // implementation of members: A::A (const string& name) : base(), persistent_table() { if (name == "") return; base::operator= (persistent_table::load (name)); } A_rep::~A_rep() { persistent_table::unload (_name); } int main() { persistent_table::set_verbose (true); // trace table load/unload A a("a"); // "a" created { A b("b"); // "b" created A c("a"); // "a" reused from table } // "b" destroyed and erased from table { A b("b"); // "b" created A c("a"); // "a" reused from table } // "b" destroyed and erased from table } // "a" destroyed and erased from table .fi .PP .SH "IMPLEMENTATION" .PP This documentation has been generated from file util/lib/persistent_table\&.h .PP .PP .nf template class persistent_table { public: static A load (const std::string& name); static void unload (const std::string& name); static bool verbose () { return _verbose; } static void set_verbose (bool v) { _verbose = v; } protected: using loaded_map_type = std::unordered_map; static loaded_map_type& get_loaded_map() { return _loaded_map; } // data: static loaded_map_type _loaded_map; static bool _verbose; }; .fi .PP .SH AUTHOR Pierre Saramito .SH COPYRIGHT Copyright (C) 2000-2018 Pierre Saramito GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.