Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::tracked_storage< ContainerType > Class Template Reference

tracks the size of storage allocated to its underlying multi_index More...

#include <tracked_storage.hpp>

Public Types

typedef ContainerType::template nth_index< 0 >::type primary_index_type
 

Public Member Functions

 tracked_storage ()=default
 
bool read (fc::cfile_datastream &ds, size_t max_memory)
 
void write (fc::cfile &dat_content) const
 
std::pair< typename primary_index_type::iterator, bool > insert (typename ContainerType::value_type obj)
 
template<typename Key >
primary_index_type::iterator find (const Key &key)
 
template<typename Key >
primary_index_type::const_iterator find (const Key &key) const
 
template<typename Lam >
void modify (typename primary_index_type::iterator itr, Lam lam)
 
template<typename Key >
void erase (const Key &key)
 
void erase (typename primary_index_type::iterator itr)
 
size_t memory_size () const
 
const ContainerType & index () const
 

Detailed Description

template<typename ContainerType>
class fc::tracked_storage< ContainerType >

This class wraps a multi_index container and tracks the memory allocated as the container creates, modifies, and deletes. It also provides read and write methods for persistence.

Requires ContainerType::value_type to have a size() method that represents the memory used for that object or specialized tracked::size() and is required to be a pack/unpack-able type.

Definition at line 35 of file tracked_storage.hpp.

Member Typedef Documentation

◆ primary_index_type

template<typename ContainerType >
ContainerType::template nth_index<0>::type fc::tracked_storage< ContainerType >::primary_index_type

Definition at line 40 of file tracked_storage.hpp.

Constructor & Destructor Documentation

◆ tracked_storage()

template<typename ContainerType >
fc::tracked_storage< ContainerType >::tracked_storage ( )
default

Member Function Documentation

◆ erase() [1/2]

template<typename ContainerType >
template<typename Key >
void fc::tracked_storage< ContainerType >::erase ( const Key & key)
inline

Definition at line 102 of file tracked_storage.hpp.

102 {
103 auto itr = _index.find(key);
104 if (itr == _index.end())
105 return;
106
107 _memory_size -= tracked::memory_size(*itr);
108 _index.erase(itr);
109 }
size_t memory_size(const T &obj)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [2/2]

template<typename ContainerType >
void fc::tracked_storage< ContainerType >::erase ( typename primary_index_type::iterator itr)
inline

Definition at line 111 of file tracked_storage.hpp.

111 {
112 _memory_size -= tracked::memory_size(*itr);
113 _index.erase(itr);
114 }
Here is the call graph for this function:

◆ find() [1/2]

template<typename ContainerType >
template<typename Key >
primary_index_type::iterator fc::tracked_storage< ContainerType >::find ( const Key & key)
inline

Definition at line 82 of file tracked_storage.hpp.

82 {
83 primary_index_type& primary_idx = _index.template get<0>();
84 return primary_idx.find(key);
85 }
ContainerType::template nth_index< 0 >::type primary_index_type
Here is the caller graph for this function:

◆ find() [2/2]

template<typename ContainerType >
template<typename Key >
primary_index_type::const_iterator fc::tracked_storage< ContainerType >::find ( const Key & key) const
inline

Definition at line 88 of file tracked_storage.hpp.

88 {
89 const primary_index_type& primary_idx = _index.template get<0>();
90 return primary_idx.find(key);
91 }

◆ index()

template<typename ContainerType >
const ContainerType & fc::tracked_storage< ContainerType >::index ( ) const
inline

Definition at line 120 of file tracked_storage.hpp.

120 {
121 return _index;
122 }
Here is the caller graph for this function:

◆ insert()

template<typename ContainerType >
std::pair< typename primary_index_type::iterator, bool > fc::tracked_storage< ContainerType >::insert ( typename ContainerType::value_type obj)
inline

Definition at line 72 of file tracked_storage.hpp.

72 {
73 const auto size = tracked::memory_size(obj);
74 auto result = _index.insert(std::move(obj));
75 if (result.second) {
76 _memory_size += size;
77 }
78 return result;
79 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_size()

template<typename ContainerType >
size_t fc::tracked_storage< ContainerType >::memory_size ( ) const
inline

Definition at line 116 of file tracked_storage.hpp.

116 {
117 return _memory_size;
118 }
Here is the caller graph for this function:

◆ modify()

template<typename ContainerType >
template<typename Lam >
void fc::tracked_storage< ContainerType >::modify ( typename primary_index_type::iterator itr,
Lam lam )
inline

Definition at line 94 of file tracked_storage.hpp.

94 {
95 _memory_size -= tracked::memory_size(*itr);
96 if (_index.modify( itr, std::move(lam))) {
97 _memory_size += tracked::memory_size(*itr);
98 }
99 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

template<typename ContainerType >
bool fc::tracked_storage< ContainerType >::read ( fc::cfile_datastream & ds,
size_t max_memory )
inline

Definition at line 47 of file tracked_storage.hpp.

47 {
48 auto container_size = _index.size();
49 fc::raw::unpack(ds, container_size);
50 for (size_t i = 0; i < container_size; ++i) {
51 if (memory_size() >= max_memory) {
52 return false;
53 }
54 typename ContainerType::value_type v;
55 fc::raw::unpack(ds, v);
56 insert(std::move(v));
57 }
58
59 return true;
60 }
size_t memory_size() const
std::pair< typename primary_index_type::iterator, bool > insert(typename ContainerType::value_type obj)
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
Here is the call graph for this function:

◆ write()

template<typename ContainerType >
void fc::tracked_storage< ContainerType >::write ( fc::cfile & dat_content) const
inline

Definition at line 62 of file tracked_storage.hpp.

62 {
63 const auto container_size = _index.size();
64 dat_content.write( reinterpret_cast<const char*>(&container_size), sizeof(container_size) );
65
66 for (const auto& item : _index) {
67 auto data = fc::raw::pack(item);
68 dat_content.write(data.data(), data.size());
69 }
70 }
void write(const char *d, size_t n)
Definition cfile.hpp:127
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
Here is the call graph for this function:

The documentation for this class was generated from the following file: