1#ifndef _RHEOLEF_PERSISTENT_TABLE_H
2#define _RHEOLEF_PERSISTENT_TABLE_H
77#include "rheolef/smart_pointer.h"
78#include <unordered_map>
86 static A load (
const std::string& name);
87 static void unload (
const std::string& name);
102 using base =
typename A::base;
103 using rep =
typename base::handled_type;
106 verbose() && std::cerr <<
"persistent_table: \""<<name<<
"\" reused from table" << std::endl;
108 a.base::operator= (base((*iter).second,
typename base::internal()));
111 verbose() && std::cerr <<
"persistent_table: \""<<name<<
"\" created" << std::endl;
112 rep* ptr = rep::make_ptr (name);
114 a.base::operator= (ptr);
115 get_loaded_map().insert (std::make_pair(name, a.base::get_count()));
123 verbose() && std::cerr <<
"persistent_table: \""<<name<<
"\" destroyed and erased from table" << std::endl;
145#ifdef _RHEOLEF_PERSISTENT_TABLE_EXAMPLE
147#include "rheolef/persistent_table.h"
154 A_rep (
const string& name1) : _name(name1) { }
156 string name()
const {
return _name; }
157 static A_rep* make_ptr (
const string& name) {
return new A_rep (name); }
162struct A :
public smart_pointer_nocopy<A_rep>,
public persistent_table<A> {
165 using base = smart_pointer_nocopy<rep>;
166 A (
const string& name =
"");
167 string name()
const {
return base::data().name(); }
170A::A (
const string& name)
172 persistent_table<
A>()
174 if (name ==
"")
return;
see the persistent_table page for the full documentation
static void unload(const std::string &name)
static void set_verbose(bool v)
std::unordered_map< std::string, void * > loaded_map_type
static loaded_map_type & get_loaded_map()
static loaded_map_type _loaded_map
static A load(const std::string &name)
This file is part of Rheolef.