environment_cache.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
27 #define TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
28 
31 #include <memory>
32 #include <deque>
33 #include <shared_mutex>
35 
36 namespace tesseract_environment
37 {
38 class Environment;
40 {
41 public:
42  using Ptr = std::shared_ptr<EnvironmentCache>;
43  using ConstPtr = std::shared_ptr<const EnvironmentCache>;
44  using UPtr = std::unique_ptr<EnvironmentCache>;
45  using ConstUPtr = std::unique_ptr<const EnvironmentCache>;
46 
47  EnvironmentCache() = default;
48  virtual ~EnvironmentCache() = default;
49  EnvironmentCache(const EnvironmentCache&) = delete;
53 
58  virtual void setCacheSize(long size) = 0;
59 
64  virtual long getCacheSize() const = 0;
65 
67  virtual void refreshCache() const = 0;
68 
73  virtual std::unique_ptr<Environment> getCachedEnvironment() const = 0;
74 };
75 
77 {
78 public:
79  using Ptr = std::shared_ptr<DefaultEnvironmentCache>;
80  using ConstPtr = std::shared_ptr<const DefaultEnvironmentCache>;
81 
82  DefaultEnvironmentCache(std::shared_ptr<const Environment> env, std::size_t cache_size = 5);
83 
88  void setCacheSize(long size) override final;
89 
94  long getCacheSize() const override final;
95 
97  void refreshCache() const override final;
98 
103  std::unique_ptr<Environment> getCachedEnvironment() const override final;
104 
105 protected:
107  std::shared_ptr<const Environment> env_;
108 
110  std::size_t cache_size_{ 5 };
111 
113  mutable int cache_env_revision_{ 0 };
114 
116  mutable std::deque<std::unique_ptr<Environment>> cache_;
117 
119  mutable std::shared_mutex cache_mutex_;
120 
122  void refreshCacheHelper() const;
123 };
124 } // namespace tesseract_environment
125 
126 #endif // TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
tesseract_environment::EnvironmentCache::refreshCache
virtual void refreshCache() const =0
If the environment has changed it will rebuild the cache of tesseract objects.
tesseract_environment
Definition: command.h:45
tesseract_environment::EnvironmentCache::getCacheSize
virtual long getCacheSize() const =0
Get the cache size used to hold tesseract objects for motion planning.
tesseract_environment::DefaultEnvironmentCache::env_
std::shared_ptr< const Environment > env_
The tesseract_object used to create the cache.
Definition: environment_cache.h:107
tesseract_environment::EnvironmentCache
Definition: environment_cache.h:39
tesseract_environment::DefaultEnvironmentCache::getCacheSize
long getCacheSize() const override final
Get the cache size used to hold tesseract objects for motion planning.
Definition: environment_cache.cpp:47
tesseract_environment::DefaultEnvironmentCache::DefaultEnvironmentCache
DefaultEnvironmentCache(std::shared_ptr< const Environment > env, std::size_t cache_size=5)
Definition: environment_cache.cpp:36
tesseract_environment::EnvironmentCache::UPtr
std::unique_ptr< EnvironmentCache > UPtr
Definition: environment_cache.h:44
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_environment::DefaultEnvironmentCache::refreshCache
void refreshCache() const override final
If the environment has changed it will rebuild the cache of tesseract objects.
Definition: environment_cache.cpp:49
tesseract_environment::EnvironmentCache::setCacheSize
virtual void setCacheSize(long size)=0
Set the cache size used to hold tesseract objects for motion planning.
tesseract_environment::EnvironmentCache::ConstUPtr
std::unique_ptr< const EnvironmentCache > ConstUPtr
Definition: environment_cache.h:45
tesseract_environment::DefaultEnvironmentCache
Definition: environment_cache.h:76
tesseract_environment::DefaultEnvironmentCache::refreshCacheHelper
void refreshCacheHelper() const
This does not take a lock.
Definition: environment_cache.cpp:71
tesseract_environment::EnvironmentCache::getCachedEnvironment
virtual std::unique_ptr< Environment > getCachedEnvironment() const =0
This will pop an Environment object from the queue.
tesseract_environment::Environment
Definition: environment.h:71
tesseract_environment::DefaultEnvironmentCache::cache_size_
std::size_t cache_size_
The assigned cache size.
Definition: environment_cache.h:110
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_environment::DefaultEnvironmentCache::cache_
std::deque< std::unique_ptr< Environment > > cache_
A vector of cached Tesseract objects.
Definition: environment_cache.h:116
tesseract_environment::EnvironmentCache::~EnvironmentCache
virtual ~EnvironmentCache()=default
tesseract_environment::DefaultEnvironmentCache::cache_env_revision_
int cache_env_revision_
The environment revision number at the time the cache was populated.
Definition: environment_cache.h:113
tesseract_environment::EnvironmentCache::Ptr
std::shared_ptr< EnvironmentCache > Ptr
Definition: environment_cache.h:42
tesseract_environment::DefaultEnvironmentCache::getCachedEnvironment
std::unique_ptr< Environment > getCachedEnvironment() const override final
This will pop an Environment object from the queue.
Definition: environment_cache.cpp:55
tesseract_environment::EnvironmentCache::EnvironmentCache
EnvironmentCache()=default
tesseract_environment::EnvironmentCache::ConstPtr
std::shared_ptr< const EnvironmentCache > ConstPtr
Definition: environment_cache.h:43
macros.h
tesseract_environment::DefaultEnvironmentCache::setCacheSize
void setCacheSize(long size) override final
Set the cache size used to hold tesseract objects for motion planning.
Definition: environment_cache.cpp:41
tesseract_environment::DefaultEnvironmentCache::cache_mutex_
std::shared_mutex cache_mutex_
The mutex used when reading and writing to cache_.
Definition: environment_cache.h:119
tesseract_environment::EnvironmentCache::operator=
EnvironmentCache & operator=(const EnvironmentCache &)=delete


tesseract_environment
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:21