[bfdf0c]: libpp / name_storage.h Maximize Restore History

Download this file

name_storage.h    108 lines (81 with data), 2.7 kB

  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
100
101
102
103
104
105
106
107
/**
* @file name_storage.h
* Type-safe unique storage of global names (filenames and symbols)
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author Philippe Elie
* @author John Levon
*/
#ifndef NAME_STORAGE_H
#define NAME_STORAGE_H
#include <string>
#include "unique_storage.h"
/// store original name and processed name
struct stored_name {
stored_name(std::string const & n = std::string())
: name(n) {}
bool operator<(stored_name const & rhs) const {
return name < rhs.name;
}
std::string name;
mutable std::string name_processed;
};
/// partial specialization for unique storage of names
template<typename I> class name_storage
: public unique_storage<I, stored_name> {
public:
typedef typename unique_storage<I, stored_name>::id_value id_value;
std::string const & name(id_value const & id) const {
return unique_storage<I, stored_name>::get(id).name;
};
};
struct debug_name_tag;
/// a debug filename
typedef name_storage<debug_name_tag>::id_value debug_name_id;
/// class storing a set of shared debug name (source filename)
class debug_name_storage : public name_storage<debug_name_tag> {
public:
/// return the basename for the given ID
std::string const & basename(debug_name_id id) const;
};
struct image_name_tag;
/// an image name
typedef name_storage<image_name_tag>::id_value image_name_id;
/// class storing a set of shared image name
class image_name_storage : public name_storage<image_name_tag> {
public:
/// return the basename name for the given ID
std::string const & basename(image_name_id) const;
};
struct symbol_name_tag;
/// a (demangled) symbol
typedef name_storage<symbol_name_tag>::id_value symbol_name_id;
/// class storing a set of shared symbol name
class symbol_name_storage : public name_storage<symbol_name_tag> {
public:
/// return the demangled name for the given ID
std::string const & demangle(symbol_name_id id) const;
};
/// for images
extern image_name_storage image_names;
/// for debug filenames i.e. source filename
extern debug_name_storage debug_names;
/// for symbols
extern symbol_name_storage symbol_names;
/**
* debug name specialisation for comparison.
*
* We compare by name rather by id since what user will see are
* filename and when the criteria "samples count" give identical
* result it's better to obtain result sorted by the user visible
* property filename rather than by an obscure, invisible from user
* point of view, file identifier property
*/
template<> inline bool
debug_name_id::operator<(debug_name_id const & rhs) const
{
return debug_names.name(*this) < debug_names.name(rhs);
}
#endif /* !NAME_STORAGE_H */