OpenSubdiv
Loading...
Searching...
No Matches
surfaceFactoryCache.h
Go to the documentation of this file.
1
//
2
// Copyright 2021 Pixar
3
//
4
// Licensed under the terms set forth in the LICENSE.txt file available at
5
// https://opensubdiv.org/license.
6
//
7
8
#ifndef OPENSUBDIV3_BFR_SURFACE_FACTORY_CACHE_H
9
#define OPENSUBDIV3_BFR_SURFACE_FACTORY_CACHE_H
10
11
#include "../version.h"
12
13
#include "../bfr/irregularPatchType.h"
14
15
#include <map>
16
#include <cstdint>
17
18
namespace
OpenSubdiv
{
19
namespace
OPENSUBDIV_VERSION
{
20
21
namespace
Bfr
{
22
35
//
36
// Initial/expected use requires simple searches of and additions to the
37
// cache by the SurfaceFactory or its Builders. Longer term, with the
38
// possibility of instances of caches being shared between meshes and
39
// factories, additional options and/or public methods may be warranted
40
// to limit what is cached or to prune the cache if it gets too large.
41
//
42
class
SurfaceFactoryCache
{
43
public
:
44
SurfaceFactoryCache
();
45
virtual
~SurfaceFactoryCache
();
46
47
SurfaceFactoryCache
(
SurfaceFactoryCache
const
&) =
delete
;
48
SurfaceFactoryCache
&
operator=
(
SurfaceFactoryCache
const
&) =
delete
;
49
50
protected
:
52
// Access restricted to the Factory, its Builders, etc.
53
friend
class
SurfaceFactory
;
54
55
typedef
std::uint64_t KeyType;
56
typedef
internal::IrregularPatchSharedPtr DataType;
58
59
protected
:
61
size_t
Size()
const
{
return
_map.size(); }
62
63
//
64
// Potential overrides by subclasses for thread-safety:
65
//
66
virtual
DataType Find(KeyType
const
& key)
const
;
67
virtual
DataType Add(KeyType
const
& key, DataType
const
& data);
68
69
//
70
// Common implementation used by all subclasses:
71
//
72
DataType find(KeyType
const
& key)
const
;
73
DataType add(KeyType
const
& key, DataType
const
& data);
75
76
private
:
77
typedef
std::map<KeyType, DataType> MapType;
78
79
MapType _map;
80
};
81
96
// Separate read and write locks are provided to support mutex types
97
// allowing shared (read) or exclusive (write) access.
98
//
99
template
<
class
MUTEX_TYPE,
class
READ_LOCK_GUARD_TYPE,
100
class
WRITE_LOCK_GUARD_TYPE>
101
class
SurfaceFactoryCacheThreaded
:
public
SurfaceFactoryCache
{
102
public
:
103
SurfaceFactoryCacheThreaded
() :
SurfaceFactoryCache
() { }
104
~SurfaceFactoryCacheThreaded
()
override
=
default
;
105
106
protected
:
108
//
109
// Virtual overrides from base:
110
//
111
DataType Find(KeyType
const
& key)
const override
{
112
READ_LOCK_GUARD_TYPE lockGuard(_mutex);
113
return
find(key);
114
}
115
116
DataType Add(KeyType
const
& key, DataType
const
& data)
override
{
117
WRITE_LOCK_GUARD_TYPE lockGuard(_mutex);
118
return
add(key, data);
119
}
121
122
private
:
123
MUTEX_TYPE
mutable
_mutex;
124
};
125
126
}
// end namespace Bfr
127
128
}
// end namespace OPENSUBDIV_VERSION
129
using namespace
OPENSUBDIV_VERSION
;
130
131
}
// end namespace OpenSubdiv
132
133
#endif
/* OPENSUBDIV3_BFR_SURFACE_FACTORY_CACHE_H */
OpenSubdiv
Definition
limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition
limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition
limits.h:18
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory
Base class providing initialization of a Surface for each face of a mesh.
Definition
surfaceFactory.h:86
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCache::SurfaceFactoryCache
SurfaceFactoryCache()
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCache::~SurfaceFactoryCache
virtual ~SurfaceFactoryCache()
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCache::SurfaceFactoryCache
SurfaceFactoryCache(SurfaceFactoryCache const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCache::operator=
SurfaceFactoryCache & operator=(SurfaceFactoryCache const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCacheThreaded::SurfaceFactoryCacheThreaded
SurfaceFactoryCacheThreaded()
Definition
surfaceFactoryCache.h:103
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCacheThreaded::~SurfaceFactoryCacheThreaded
~SurfaceFactoryCacheThreaded() override=default
opensubdiv
bfr
surfaceFactoryCache.h
Generated on
for OpenSubdiv by
1.15.0