1/** 2 * @file name_storage.h 3 * Type-safe unique storage of global names (filenames and symbols) 4 * 5 * @remark Copyright 2002 OProfile authors 6 * @remark Read the file COPYING 7 * 8 * @author Philippe Elie 9 * @author John Levon 10 */ 11 12#ifndef NAME_STORAGE_H 13#define NAME_STORAGE_H 14 15#include <string> 16 17#include "unique_storage.h" 18 19class extra_images; 20 21/// store original name and processed name 22struct stored_name { 23 stored_name(std::string const & n = std::string()) 24 : name(n) {} 25 26 bool operator<(stored_name const & rhs) const { 27 return name < rhs.name; 28 } 29 30 std::string name; 31 mutable std::string name_processed; 32}; 33 34 35/// partial specialization for unique storage of names 36template <typename I> struct name_storage : unique_storage<I, stored_name> { 37 38 typedef typename unique_storage<I, stored_name>::id_value id_value; 39 40 std::string const & name(id_value const & id) const { 41 return unique_storage<I, stored_name>::get(id).name; 42 } 43}; 44 45 46class debug_name_tag; 47/// a debug filename 48typedef name_storage<debug_name_tag>::id_value debug_name_id; 49 50/// class storing a set of shared debug name (source filename) 51struct debug_name_storage : name_storage<debug_name_tag> { 52 /// return the basename for the given ID 53 std::string const & basename(debug_name_id id) const; 54}; 55 56/// store original name and processed name 57struct stored_filename { 58 stored_filename(std::string const & n = std::string()) 59 : filename(n), extra_images_uid(0) {} 60 61 bool operator<(stored_filename const & rhs) const { 62 return filename < rhs.filename; 63 } 64 65 std::string filename; 66 mutable std::string base_filename; 67 mutable std::string real_filename; 68 mutable std::string real_base_filename; 69 mutable int extra_images_uid; 70}; 71 72/// partial specialization for unique storage of filenames 73template <typename I> 74struct filename_storage : unique_storage<I, stored_filename> { 75 76 typedef typename unique_storage<I, stored_filename>::id_value id_value; 77 78 std::string const & name(id_value const & id) const { 79 return unique_storage<I, stored_filename>::get(id).filename; 80 } 81}; 82 83class image_name_tag; 84/// an image name 85typedef filename_storage<image_name_tag>::id_value image_name_id; 86 87/// class storing a set of shared image name 88struct image_name_storage : filename_storage<image_name_tag> { 89 enum image_name_type { 90 /// image name based on the sample filename w/o path 91 int_basename, 92 /// image name based on the sample filename 93 int_filename, 94 /// real image name, can be different for module. 95 int_real_basename, 96 /// same as int_real_basename + the complete path, including an 97 /// optionnal archive_path passed trough profile_spec 98 int_real_filename, 99 }; 100 101 /** 102 * @param id the image name id 103 * @param type the image name type 104 * @param extra extra locations where the image can be found 105 * 106 * If type == int_real_name (resp. int_real_filename) and the image 107 * can't be located the return value is the same as if get_name() 108 * was called with int_name (resp. int_filename). 109 * 110 * multiple call with the image_name_id and different extra parameter 111 * will throw a runtime error, multiple extra_images are possible 112 * with differential profile but the name. FIXME 113 */ 114 std::string const & get_name(image_name_id id, 115 image_name_type type, 116 extra_images const & extra) const; 117 118 /// return the basename name for the given ID 119 std::string const & basename(image_name_id) const; 120}; 121 122 123class symbol_name_tag; 124/// a (demangled) symbol 125typedef name_storage<symbol_name_tag>::id_value symbol_name_id; 126 127/// class storing a set of shared symbol name 128struct symbol_name_storage : name_storage<symbol_name_tag> { 129 /// return the demangled name for the given ID 130 std::string const & demangle(symbol_name_id id) const; 131}; 132 133 134/// for images 135extern image_name_storage image_names; 136 137/// for debug filenames i.e. source filename 138extern debug_name_storage debug_names; 139 140/// for symbols 141extern symbol_name_storage symbol_names; 142 143 144/** 145 * debug name specialisation for comparison. 146 * 147 * We compare by name rather by id since what user will see are 148 * filename and when the criteria "samples count" give identical 149 * result it's better to obtain result sorted by the user visible 150 * property filename rather than by an obscure, invisible from user 151 * point of view, file identifier property 152 */ 153template<> inline bool 154debug_name_id::operator<(debug_name_id const & rhs) const 155{ 156 return debug_names.name(*this) < debug_names.name(rhs); 157} 158 159#endif /* !NAME_STORAGE_H */ 160