HPCToolkit
FileNameMap.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // global includes
3 //------------------------------------------------------------------------------
4 
5 #include <map>
6 #include <string>
7 #include <string.h>
8 
9 
10 
11 //------------------------------------------------------------------------------
12 // local includes
13 //------------------------------------------------------------------------------
14 
15 #include "realpath.h"
16 
17 
18 
19 //------------------------------------------------------------------------------
20 // types
21 //------------------------------------------------------------------------------
22 
24 public:
25  bool operator()(const char *n1, const char *n2) const {
26  return strcmp(n1,n2) < 0;
27  }
28 };
29 
30 
31 
32 //------------------------------------------------------------------------------
33 // private data
34 //------------------------------------------------------------------------------
35 
36 // ---------------------------------------------------
37 // map for interning character strings for file names
38 // ---------------------------------------------------
39 
40 static std::map<const char *, std::string *, FilenameCompare> fileNameMap;
41 
42 
43 
44 //------------------------------------------------------------------------------
45 // interface functions
46 //------------------------------------------------------------------------------
47 std::string &getRealPath(const char *name)
48 {
49  std::string *&thename = fileNameMap[name];
50  if (thename == NULL) {
51  // the filename is not in the list. Add it.
52  thename = new std::string(RealPath(name));
53  }
54  return *thename;
55 }
bool operator()(const char *n1, const char *n2) const
Definition: FileNameMap.cpp:25
static std::map< const char *, std::string *, FilenameCompare > fileNameMap
Definition: FileNameMap.cpp:40
const char * RealPath(const char *nm)
Definition: realpath.c:69
#define NULL
Definition: ElfHelper.cpp:85
std::string & getRealPath(const char *name)
Definition: FileNameMap.cpp:47