Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
medialibrary
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
31
Issues
31
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VideoLAN
medialibrary
Commits
01fdddd0
Commit
01fdddd0
authored
Dec 28, 2015
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: Add a Cache class
parent
6fa38e62
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
src/utils/Cache.h
src/utils/Cache.h
+75
-0
No files found.
src/utils/Cache.h
0 → 100644
View file @
01fdddd0
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include <mutex>
#include <cassert>
template
<
typename
T
>
class
Cache
{
public:
Cache
()
:
m_cached
(
false
)
{}
bool
isCached
()
const
{
return
m_cached
;
}
operator
T
()
const
{
assert
(
m_cached
);
return
m_value
;
}
operator
const
T
&
()
const
{
return
m_value
;
}
const
T
&
get
()
const
{
return
m_value
;
}
T
&
get
()
{
return
m_value
;
}
template
<
typename
U
>
T
&
operator
=
(
U
&&
value
)
{
static_assert
(
std
::
is_same
<
typename
std
::
decay
<
T
>::
type
,
typename
std
::
decay
<
U
>::
type
>::
value
,
"Mismatching types"
);
m_value
=
std
::
forward
<
U
>
(
value
);
m_cached
=
true
;
return
m_value
;
}
std
::
unique_lock
<
std
::
mutex
>
lock
()
{
return
std
::
unique_lock
<
std
::
mutex
>
(
m_lock
);
}
private:
T
m_value
;
std
::
mutex
m_lock
;
bool
m_cached
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment