Doxygen
Loading...
Searching...
No Matches
filename.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef FILENAME_H
17#define FILENAME_H
18
19#include <memory>
20#include <vector>
21
22#include "dstring.h"
23#include "linkedmap.h"
24#include "utf8.h"
25#include "util.h"
26
27class FileDef;
28
29/** Class representing all files with a certain base name */
30class FileName final : public std::vector< std::unique_ptr<FileDef> >
31{
32 public:
33 explicit FileName(const DString &nm) : m_name(nm) {}
34 DString fileName() const { return m_name; }
35
36 private:
38};
39
40//! Custom combined key compare and hash functor that uses a lower case string in
41//! case CASE_SENSE_NAMES is set to NO.
43{
44 public:
45 //! used as hash function
46 std::size_t operator()(const std::string& input) const noexcept
47 {
48 return std::hash<std::string>()(searchKey(input));
49 }
50 //! used as equal operator
51 bool operator() (const std::string &t1, const std::string &t2) const
52 {
53 return searchKey(t1) == searchKey(t2);
54 }
55 private:
56 std::string searchKey(const std::string &input) const
57 {
58 std::string key = input;
59 if (!useCaseSenseNames())
60 {
61 key = convertUTF8ToLower(key);
62 }
63 return key;
64 }
65};
66
67/** Ordered dictionary of FileName objects. */
68class FileNameLinkedMap final : public LinkedMap<FileName,FileNameFn,FileNameFn,
69 std::unordered_multimap<std::string,FileName*,FileNameFn,FileNameFn> >
70{
71 public:
72 /** Returns the file definition in \a fnMap that matches the file name \a n.
73 * If there are multiple matches, ambig is set to true and the first match is returned.
74 * If there are no matches, ambig is set to false and nullptr is returned.
75 */
76 FileDef *findFileDef(const DString &n,bool &ambig) const;
77
78 /** Returns a list of file definitions in \a fnMap that match the file name \a n.
79 * The list is returned as a string with each file definition separated by a newline character.
80 * Used for error messages.
81 */
82 DString showFileDefMatches(const DString &n) const;
83};
84
85#endif
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
A model of a file symbol.
Definition filedef.h:97
std::string searchKey(const std::string &input) const
Definition filename.h:56
std::size_t operator()(const std::string &input) const noexcept
used as hash function
Definition filename.h:46
FileName(const DString &nm)
Definition filename.h:33
DString m_name
Definition filename.h:37
DString fileName() const
Definition filename.h:34
Ordered dictionary of FileName objects.
Definition filename.h:70
DString showFileDefMatches(const DString &n) const
Returns a list of file definitions in fnMap that match the file name n.
Definition filename.cpp:129
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Definition filename.cpp:36
Container class representing a vector of objects with keys.
Definition linkedmap.h:36
std::string convertUTF8ToLower(const std::string &input)
Converts the input string into a lower case version, also taking into account non-ASCII characters th...
Definition utf8.cpp:188
Various UTF8 related helper functions.
bool useCaseSenseNames()
Returns true if the names of the symbols can be case sensitive.
Definition util.cpp:2681
A bunch of utility functions.