blob: 07f02a781f3d3aa09329ac99acbc6461afafa03b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* @author Peter Boros
* @date 2004/10/01
* @version $Id$
* @file metadatamanager.h
* @brief Metadata manager class definition.
*
*/
#pragma once
#include <string>
#include <map>
#include "singleton.h"
#include "rwlock.h"
#include "metadatahandle.h"
namespace fsa {
// {{{ class MetaDataManager
/**
* @class MetaDataManager
* @brief Class for managing generic metadata.
*
* This class provides a single point of access to all metadata
* used by the applications.
*/
class MetaDataManager : public Singleton<MetaDataManager> {
protected:
friend class Singleton<MetaDataManager>;
/** Default constructor. Protected to avoid accidental creation */
MetaDataManager() : _library(), _lock() {}
private:
/** Private unimplemented copy constructor */
MetaDataManager(const MetaDataManager&);
/** Private unimplemented assignment operator */
MetaDataManager& operator=(const MetaDataManager&);
/** %MetaData library type */
using Library = std::map<std::string,MetaData::Handle*>;
/** %MetaData library iterator type */
using LibraryIterator = std::map<std::string,MetaData::Handle*>::iterator;
/** %MetaData library const iterator type */
using LibraryConstIterator = std::map<std::string,MetaData::Handle*>::const_iterator;
Library _library; /**< Library of MetaData objects. */
mutable RWLock _lock; /**< Read-write lock for library synchronization. */
public:
/** Destructor */
~MetaDataManager();
/**
* @brief Load a metadata file into memory.
*
* @param id MetaData id (to be used in later get() or drop() calls).
* @param datafile Metadata file name
*/
bool load(const std::string &id, const std::string &datafile);
/**
* @brief Get a handle to metadata.
*
* @param id Metadata id.
* @return Newly allocated handle, must be deleted by the
* caller. (NULL if no metadata with the given id was found.)
*/
MetaData::Handle* get(const std::string &id) const;
/**
* @brief Drop a metadata from the library.
*
* Drop a metadata from the library. The metadata object will
* be deleted automagically when there are no more handles referring
* to it.
*
* @param id MetaData id.
*/
void drop(const std::string &id);
/**
* @brief Drop all metadatas from the library.
*/
void clear();
};
// }}}
} // namespace fsa
|