VTK
9.3.1
Main Page
Related Pages
Topics
Namespaces
Classes
Files
File List
File Members
IO
CGNS
vtkCGNSCache.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2
// SPDX-License-Identifier: BSD-3-Clause
3
14
#ifndef vtkCGNSCache_h
15
#define vtkCGNSCache_h
16
17
#include "
vtkSmartPointer.h
"
18
19
#include <iterator>
20
#include <sstream>
21
#include <string>
22
#include <unordered_map>
23
24
namespace
CGNSRead
25
{
26
VTK_ABI_NAMESPACE_BEGIN
27
// No priority and no size limit right now
28
29
template
<
typename
CacheDataType>
30
class
vtkCGNSCache
31
{
32
public
:
33
vtkCGNSCache
();
34
35
vtkSmartPointer<CacheDataType>
Find
(
const
std::string& query);
36
37
void
Insert
(
const
std::string& key,
const
vtkSmartPointer<CacheDataType>
& data);
38
39
void
ClearCache
();
40
41
void
SetCacheSizeLimit
(
int
size);
42
int
GetCacheSizeLimit
();
43
44
private
:
45
vtkCGNSCache
(
const
vtkCGNSCache
&) =
delete
;
46
void
operator=(
const
vtkCGNSCache
&) =
delete
;
47
48
typedef
std::unordered_map<std::string, vtkSmartPointer<CacheDataType>> CacheMapper;
49
CacheMapper CacheData;
50
51
typename
CacheMapper::iterator LastCacheAccess;
52
53
int
cacheSizeLimit;
54
};
55
56
template
<
typename
CacheDataType>
57
vtkCGNSCache<CacheDataType>::vtkCGNSCache
()
58
: CacheData()
59
{
60
this->cacheSizeLimit = -1;
61
this->LastCacheAccess = CacheData.end();
62
}
63
64
template
<
typename
CacheDataType>
65
void
vtkCGNSCache<CacheDataType>::SetCacheSizeLimit
(
int
size)
66
{
67
this->cacheSizeLimit = size;
68
}
69
70
template
<
typename
CacheDataType>
71
int
vtkCGNSCache<CacheDataType>::GetCacheSizeLimit
()
72
{
73
return
this->cacheSizeLimit;
74
}
75
76
template
<
typename
CacheDataType>
77
vtkSmartPointer<CacheDataType>
vtkCGNSCache<CacheDataType>::Find
(
const
std::string& query)
78
{
79
typename
CacheMapper::iterator iter;
80
iter = this->CacheData.find(query);
81
if
(iter == this->CacheData.end())
82
return
vtkSmartPointer<CacheDataType>
(
nullptr
);
83
this->LastCacheAccess = iter;
84
return
iter->second;
85
}
86
87
template
<
typename
CacheDataType>
88
void
vtkCGNSCache<CacheDataType>::Insert
(
89
const
std::string& key,
const
vtkSmartPointer<CacheDataType>
& data)
90
{
91
92
if
(this->cacheSizeLimit > 0 &&
93
this->CacheData.size() >=
static_cast<
size_t
>
(this->cacheSizeLimit))
94
{
95
// Make some room by removing last accessed/inserted item
96
this->CacheData.erase(this->LastCacheAccess);
97
}
98
this->CacheData[key] = data;
99
this->LastCacheAccess = this->CacheData.find(key);
100
}
101
102
template
<
typename
CacheDataType>
103
void
vtkCGNSCache<CacheDataType>::ClearCache
()
104
{
105
this->CacheData.clear();
106
}
107
VTK_ABI_NAMESPACE_END
108
}
109
#endif
// vtkCGNSCache_h
110
// VTK-HeaderTest-Exclude: vtkCGNSCache.h
CGNSRead::vtkCGNSCache
Definition
vtkCGNSCache.h:31
CGNSRead::vtkCGNSCache::GetCacheSizeLimit
int GetCacheSizeLimit()
Definition
vtkCGNSCache.h:71
CGNSRead::vtkCGNSCache::Find
vtkSmartPointer< CacheDataType > Find(const std::string &query)
Definition
vtkCGNSCache.h:77
CGNSRead::vtkCGNSCache::ClearCache
void ClearCache()
Definition
vtkCGNSCache.h:103
CGNSRead::vtkCGNSCache::Insert
void Insert(const std::string &key, const vtkSmartPointer< CacheDataType > &data)
Definition
vtkCGNSCache.h:88
CGNSRead::vtkCGNSCache::SetCacheSizeLimit
void SetCacheSizeLimit(int size)
Definition
vtkCGNSCache.h:65
CGNSRead::vtkCGNSCache::vtkCGNSCache
vtkCGNSCache()
Definition
vtkCGNSCache.h:57
vtkSmartPointer
Hold a reference to a vtkObjectBase instance.
Definition
vtkSmartPointer.h:32
CGNSRead
This file defines functions used by vtkCGNSReader and vtkCGNSReaderInternal.
Definition
cgio_helpers.h:19
vtkSmartPointer.h
Generated on Fri Oct 25 2024 00:00:00 for VTK by
1.12.0