VTK
9.2.6
Main Page
Related Pages
Topics
Namespaces
Classes
Files
File List
File Members
IO
CGNS
vtkCGNSCache.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Visualization Toolkit
4
Module: vtkCGNSCache.h
5
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
All rights reserved.
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10
This software is distributed WITHOUT ANY WARRANTY; without even
11
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
PURPOSE. See the above copyright notice for more information.
13
14
=========================================================================*/
15
26
#ifndef vtkCGNSCache_h
27
#define vtkCGNSCache_h
28
29
#include "
vtkSmartPointer.h
"
30
31
#include <iterator>
32
#include <sstream>
33
#include <string>
34
#include <unordered_map>
35
36
namespace
CGNSRead
37
{
38
// No priority and no size limit right now
39
40
template
<
typename
CacheDataType>
41
class
vtkCGNSCache
42
{
43
public
:
44
vtkCGNSCache
();
45
46
vtkSmartPointer<CacheDataType>
Find
(
const
std::string& query);
47
48
void
Insert
(
const
std::string& key,
const
vtkSmartPointer<CacheDataType>
& data);
49
50
void
ClearCache
();
51
52
void
SetCacheSizeLimit
(
int
size);
53
int
GetCacheSizeLimit
();
54
55
private
:
56
vtkCGNSCache
(
const
vtkCGNSCache
&) =
delete
;
57
void
operator=(
const
vtkCGNSCache
&) =
delete
;
58
59
typedef
std::unordered_map<std::string, vtkSmartPointer<CacheDataType>> CacheMapper;
60
CacheMapper CacheData;
61
62
typename
CacheMapper::iterator LastCacheAccess;
63
64
int
cacheSizeLimit;
65
};
66
67
template
<
typename
CacheDataType>
68
vtkCGNSCache<CacheDataType>::vtkCGNSCache
()
69
: CacheData()
70
{
71
this->cacheSizeLimit = -1;
72
this->LastCacheAccess = CacheData.end();
73
}
74
75
template
<
typename
CacheDataType>
76
void
vtkCGNSCache<CacheDataType>::SetCacheSizeLimit
(
int
size)
77
{
78
this->cacheSizeLimit = size;
79
}
80
81
template
<
typename
CacheDataType>
82
int
vtkCGNSCache<CacheDataType>::GetCacheSizeLimit
()
83
{
84
return
this->cacheSizeLimit;
85
}
86
87
template
<
typename
CacheDataType>
88
vtkSmartPointer<CacheDataType>
vtkCGNSCache<CacheDataType>::Find
(
const
std::string& query)
89
{
90
typename
CacheMapper::iterator iter;
91
iter = this->CacheData.find(query);
92
if
(iter == this->CacheData.end())
93
return
vtkSmartPointer<CacheDataType>
(
nullptr
);
94
this->LastCacheAccess = iter;
95
return
iter->second;
96
}
97
98
template
<
typename
CacheDataType>
99
void
vtkCGNSCache<CacheDataType>::Insert
(
100
const
std::string& key,
const
vtkSmartPointer<CacheDataType>
& data)
101
{
102
103
if
(this->cacheSizeLimit > 0 &&
104
this->CacheData.size() >=
static_cast<
size_t
>
(this->cacheSizeLimit))
105
{
106
// Make some room by removing last accessed/inserted item
107
this->CacheData.erase(this->LastCacheAccess);
108
}
109
this->CacheData[key] = data;
110
this->LastCacheAccess = this->CacheData.find(key);
111
}
112
113
template
<
typename
CacheDataType>
114
void
vtkCGNSCache<CacheDataType>::ClearCache
()
115
{
116
this->CacheData.clear();
117
}
118
}
119
#endif
// vtkCGNSCache_h
120
// VTK-HeaderTest-Exclude: vtkCGNSCache.h
CGNSRead::vtkCGNSCache
Definition
vtkCGNSCache.h:42
CGNSRead::vtkCGNSCache::GetCacheSizeLimit
int GetCacheSizeLimit()
Definition
vtkCGNSCache.h:82
CGNSRead::vtkCGNSCache::Find
vtkSmartPointer< CacheDataType > Find(const std::string &query)
Definition
vtkCGNSCache.h:88
CGNSRead::vtkCGNSCache::ClearCache
void ClearCache()
Definition
vtkCGNSCache.h:114
CGNSRead::vtkCGNSCache::Insert
void Insert(const std::string &key, const vtkSmartPointer< CacheDataType > &data)
Definition
vtkCGNSCache.h:99
CGNSRead::vtkCGNSCache::SetCacheSizeLimit
void SetCacheSizeLimit(int size)
Definition
vtkCGNSCache.h:76
CGNSRead::vtkCGNSCache::vtkCGNSCache
vtkCGNSCache()
Definition
vtkCGNSCache.h:68
vtkSmartPointer
Hold a reference to a vtkObjectBase instance.
Definition
vtkSmartPointer.h:42
CGNSRead
Definition
cgio_helpers.h:39
vtkSmartPointer.h
Generated on Sat Jun 8 2024 00:00:00 for VTK by
1.11.0