Helios++
Helios software for LiDAR simulations
WavefrontObjCache.h
1 //
2 // Created by miguelyermo on 23/6/21.
3 //
4 
5 #ifndef HELIOS_WAVEFRONTOBJCACHE_H
6 #define HELIOS_WAVEFRONTOBJCACHE_H
7 
8 #include <string>
9 #include "WavefrontObj.h"
10 #include <list>
11 #include <unordered_map>
12 
13 typedef std::string key_type;
14 typedef WavefrontObj *value_type;
15 typedef std::list<key_type> list_type;
16 typedef typename list_type::iterator list_iterator;
17 typedef std::unordered_map<key_type, std::pair<value_type, list_iterator>>
18  map_type;
19 typedef typename map_type::iterator map_iterator;
20 
22 
23 public:
28  size_t size() const;
29 
34  size_t capacity() const;
35 
40  bool empty() const;
41 
48  bool contains(const std::string &key);
49 
55  void insert(const std::string &key, WavefrontObj * value);
56 
62  WavefrontObj * get(const std::string &key);
63 
68  void deallocate();
69 
75 
76 private:
77  map_type m_map;
78  list_type m_list;
79  size_t m_capacity;
80 
81  // *** CONSTRUCTION / DESTRUCTION *** //
82  // ************************************ //
87 
93 };
94 
95 #endif // HELIOS_WAVEFRONTOBJCACHE_H
Definition: WavefrontObjCache.h:21
bool contains(const std::string &key)
Checks whether a value is already stored in the cache looking for its key.
Definition: WavefrontObjCache.cpp:25
size_t capacity() const
Get the maximum number of elements that can be stored in the cache.
Definition: WavefrontObjCache.cpp:21
WavefrontObjCache()
Default constructor for a default OBJ Cache.
Definition: WavefrontObjCache.cpp:12
static WavefrontObjCache & getInstance()
Get an instance of the cache (Singleton Pattern)
Definition: WavefrontObjCache.cpp:7
size_t size() const
Get the number of elements allocated in the cache.
Definition: WavefrontObjCache.cpp:19
void insert(const std::string &key, WavefrontObj *value)
Inserts an element in the cache.
Definition: WavefrontObjCache.cpp:29
bool empty() const
Checks whether the cache is empty.
Definition: WavefrontObjCache.cpp:23
void deallocate()
Removes the last element in the list to make room to a new one. This function is called only if the c...
Definition: WavefrontObjCache.cpp:75
WavefrontObj * get(const std::string &key)
Returns a cache element by its key, if exists.
Definition: WavefrontObjCache.cpp:42
~WavefrontObjCache()
Destructor with the responsibility of deallocating all the items stored in the Heap.
Definition: WavefrontObjCache.cpp:14
Class representing a .obj loaded file.
Definition: WavefrontObj.h:15