packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmSourceFileLocation.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmSourceFileLocation_h
13 #define cmSourceFileLocation_h
14
15 #include "cmStandardIncludes.h"
16
17 class cmMakefile;
18
19 /** \class cmSourceFileLocation
20  * \brief cmSourceFileLocation tracks knowledge about a source file location
21  *
22  * Source files can be referenced by a variety of names.  The
23  * directory and/or extension may be omitted leading to a certain
24  * level of ambiguity about the source file location.  This class is
25  * used by cmSourceFile to keep track of what is known about the
26  * source file location.  Each reference may add some information
27  * about the directory or extension of the file.
28  */
29 class cmSourceFileLocation
30 {
31 public:
32   /**
33    * Construct for a source file created in a given cmMakefile
34    * instance with an initial name.
35    */
36   cmSourceFileLocation(cmMakefile* mf, const char* name);
37
38   /**
39    * Return whether the givne source file location could refers to the
40    * same source file as this location given the level of ambiguity in
41    * each location.
42    */
43   bool Matches(cmSourceFileLocation const& loc);
44
45   /**
46    * Explicity state that the source file is located in the source tree.
47    */
48   void DirectoryUseSource();
49
50   /**
51    * Explicity state that the source file is located in the build tree.
52    */
53   void DirectoryUseBinary();
54
55   /**
56    * Return whether the directory containing the source is ambiguous.
57    */
58   bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
59
60   /**
61    * Return whether the extension of the source name is ambiguous.
62    */
63   bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
64
65   /**
66    * Get the directory containing the file as best is currently known.
67    * If DirectoryIsAmbiguous() returns false this will be a full path.
68    * Otherwise it will be a relative path (possibly empty) that is
69    * either with respect to the source or build tree.
70    */
71   const char* GetDirectory() const { return this->Directory.c_str(); }
72
73   /**
74    * Get the file name as best is currently known.  If
75    * ExtensionIsAmbiguous() returns true this name may not be the
76    * final name (but could be).  Otherwise the returned name is the
77    * final name.
78    */
79   const char* GetName() const { return this->Name.c_str(); }
80
81   /**
82    * Get the cmMakefile instance for which the source file was created.
83    */
84   cmMakefile* GetMakefile() const { return this->Makefile; }
85 private:
86   cmMakefile* Makefile;
87   bool AmbiguousDirectory;
88   bool AmbiguousExtension;
89   std::string Directory;
90   std::string Name;
91
92   bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
93
94   // Update the location with additional knowledge.
95   void Update(cmSourceFileLocation const& loc);
96   void Update(const char* name);
97   void UpdateExtension(const char* name);
98   void UpdateDirectory(const char* name);
99 };
100
101 #endif