Sirikata
libcore/include/sirikata/core/util/Paths.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2011 Sirikata Authors. All rights reserved.
00002 // Use of this source code is governed by a BSD-style license that can
00003 // be found in the LICENSE file.
00004 
00005 #ifndef _SIRIKATA_LIBCORE_UTIL_PATHS_HPP_
00006 #define _SIRIKATA_LIBCORE_UTIL_PATHS_HPP_
00007 
00008 #include <sirikata/core/util/Platform.hpp>
00009 
00010 namespace Sirikata {
00011 
00015 namespace Path {
00016 
00017 enum Key {
00018     PATH_START = 0,
00019 
00020     // Full path to executable file
00021     FILE_EXE,
00022     // Full path to executable file's directory
00023     DIR_EXE,
00024     // Full path to executable file's bundle. On most platform's this is
00025     // equivalent to DIR_EXE. On OS X, it gives the directory of the .app
00026     // containing the binary when it is located in one.
00027     DIR_EXE_BUNDLE,
00028     // Full path to current directory
00029     DIR_CURRENT,
00030     // Full path to a user-specific directory, e.g. /home/username
00031     DIR_USER,
00032     // Full path to a hidden directory in a user-specific location,
00033     // e.g. /home/username/.sirikata
00034     DIR_USER_HIDDEN,
00035     // Full path to temporary directory, e.g. under /tmp
00036     DIR_TEMP,
00037     // System-wide configuration directory, e.g. /etc/sirikata. Note
00038     // that this is sirikata specific.
00039     DIR_SYSTEM_CONFIG,
00040 
00041     // Path to resources directory, e.g. share/. You can't request
00042     // this path directly since it's actually a collection of in-tree
00043     // resources: calling Get(RESOURCE) will fail. Instead, you
00044     // need to use the version of Get() where you also provide an
00045     // in-tree path (e.g. liboh/plugins/) and a path which is
00046     // identical in both the in-tree and installed versions
00047     // (e.g. js/scripts).
00048     RESOURCE,
00049 
00050     PATH_END
00051 };
00052 
00057 namespace Placeholders {
00058 extern SIRIKATA_EXPORT const String DIR_EXE;
00059 extern SIRIKATA_EXPORT const String DIR_EXE_BUNDLE;
00060 extern SIRIKATA_EXPORT const String DIR_CURRENT;
00061 extern SIRIKATA_EXPORT const String DIR_USER;
00062 extern SIRIKATA_EXPORT const String DIR_USER_HIDDEN;
00063 extern SIRIKATA_EXPORT const String DIR_TEMP;
00064 extern SIRIKATA_EXPORT const String DIR_SYSTEM_CONFIG;
00065 // This one is a function because you must provide a search file or
00066 // path within the resources directory.
00067 SIRIKATA_FUNCTION_EXPORT String RESOURCE(const String& intree, const String& resource);
00068 } // namespace Placeholders
00069 
00070 SIRIKATA_FUNCTION_EXPORT String Get(Key key);
00071 // Get a path from an offset based on key, e.g. use Get(DIR_TEMP, "foo.log") to
00072 // get the equivalent of "/tmp/sirikata/foo.log".
00073 SIRIKATA_FUNCTION_EXPORT String Get(Key key, const String& relative_path);
00074 SIRIKATA_FUNCTION_EXPORT bool Set(Key key, const String& path);
00075 // Special version which is used for searching when multiple (fixed)
00076 // paths to a resource may work, e.g. because of differences in the
00077 // directory layout between in-tree and installed versions. For
00078 // example, Get(RESOURCE, "js/scripts", "liboh/plugins") could return
00079 // /home/user/sirikata/liboh/plugins/js/scripts for the in-tree
00080 // version and /usr/share/js/scripts for the installed version.
00081 SIRIKATA_FUNCTION_EXPORT String Get(Key key, const String& relative_path, const String& alternate_base);
00082 
00084 SIRIKATA_FUNCTION_EXPORT String SubstitutePlaceholders(const String& path);
00085 
00093 SIRIKATA_FUNCTION_EXPORT String GetTempFilename(const String& prefix);
00094 
00095 } // namespace Path
00096 } // namespace Sirikata
00097 
00098 #endif //_SIRIKATA_LIBCORE_UTIL_PATHS_HPP_