File: path.h

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (124 lines) | stat: -rw-r--r-- 3,702 bytes parent folder | download | duplicates (8)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: path.h,v 1.13.20.1 2007/06/21 19:38:10 oliver Exp $
//
// Author:
//   Oliver Kohlbacher
//

#ifndef BALL_COMMON_PATH_H
#define BALL_COMMON_PATH_H

#ifndef BALL_CONFIG_CONFIG_H
#	include <BALL/CONFIG/config.h>
#endif

#ifndef BALL_COMMON_GLOBAL_H
# include <BALL/COMMON/global.h>
#endif

#ifndef BALL_DATATYPE_STRING_H
# include <BALL/DATATYPE/string.h>
#endif

#include <vector>

using std::vector;

namespace BALL 
{
	/**	Data path management class.
			This class is intended to provide a unique interface to 
			directories where the data files needed by BALL reside.	 \par
			Path is a singleton, so there is only one unique application-wide
			instance of and changes to this will be seen by all classes using
			path.
	\ingroup System		
	*/
	class BALL_EXPORT Path 
	{
		public:
		/**	@name Constructors and Destructors
		*/	
		//@{
		
		/**	Default constructor
		*/
		Path();
		//@}

		/** Return a list of paths to the BALL data directories.
				This directory is set to a default value at compile time
				of the library.
				It may be overridden at runtime by setting the environment
				variable "BALL_DATA" to the desired value. This value
        is then prepended to the list of directories. 
        Directories are separated by linefeeds and returned 
        as a single string. To locate files in these directories,
        \link Path::find find \endlink will search the directories
        in the specified order.\par

				The default path may be accessed using  \link Path::getDefaultDataPath getDefaultDataPath \endlink .
				The path may also be modified at runtime by calling  \link Path::setDataPath setDataPath \endlink .\par

				The path contains a newline ("\n") separated list of paths that are searched 
				in the order of occurence. \par
		*/		
		String getDataPath();

		/**	Modify the data path.
				This method accepts a newline separated list of paths to
				specify data paths.
		*/
		void setDataPath(const String& path);

		/**	Add a single path to the list of paths.
				@param	path the path to be added to the path list
		*/
		void addDataPath(const String& path);

		/**	Returns the default data path compiled into the library.
				This method ignores possible contents of the environment
				variable "BALL\_DATA".
		*/
		String getDefaultDataPath();

		/**	Returns the full path to a file residing in one of the data directories.
				If a file that matches the name is not found, an empty string is returned.
				Directories are searched in the order of occurence in the data path.
				If <b>name</b> contains relative path information but no file matching 
				this path could be found, another search is performed as a second step
				taking in account only the basename of the file. \par
				E.g.: \par
				Specifying <b>data/test.dat</b> will search for data/test.dat in each
				data directory first. If this search doesn't yield a match, find will search 
				for a file named <b>test.dat</b> in each of the directories. \par
				If this behaviour is not desired, try  \link Path::findStrict findStrict \endlink  instead. \par
		*/
		String find(const String& name);

		/**	Returns the full path to a file residing in one of the data directories.
				@see find
		*/
		String findStrict(const String& name);

		/// Reset the path variable to its default state (as it was a the start of the application).
		void reset();

		
		protected:
				
		void buildPathArray_();

		static String path_;
		static bool path_array_valid_;
		static bool environment_checked_;
		static std::vector<String>	path_array_;
		static bool initialized_;
	};
  
} // namespace BALL


#endif // BALL_COMMON_PATH_H