X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fresource.hh;fp=src%2Fmoof%2Fresource.hh;h=ed8a7d06f8fd9a8c420d9fab59c0c54de60a0658;hp=0000000000000000000000000000000000000000;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hpb=299af4f2047e767e5d79501c26444473bda64c64 diff --git a/src/moof/resource.hh b/src/moof/resource.hh new file mode 100644 index 0000000..ed8a7d0 --- /dev/null +++ b/src/moof/resource.hh @@ -0,0 +1,89 @@ + +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ + +#ifndef _MOOF_RESOURCE_HH_ +#define _MOOF_RESOURCE_HH_ + +/** + * \file resource.hh + * Interface for textures, sounds, and other types of resources. + */ + +#include +#include +#include + + +namespace moof { + + +/** + * Generic resource class. + */ + +class resource +{ +public: + + virtual ~resource() {} + + + /** + * Add a directory to search when looking for resource files. + * \param paths A colon-separated list of directory paths. + */ + static void add_search_paths(const std::string& paths); + + /** + * Add directories to search when looking for resource files. + * \param pathList The list of directory paths. + */ + static void add_search_paths(const std::vector& pathList); + + + /** + * Get the path to a resource of a given name. + * \param path The name of the resource to find. Upon successful + * return, this is changed to an absolute path to the resource. + * \param prefix A colon-separated list of subdirectories to search. + * \param extension A colon-separated list of possible extensions. + * \return True if a path to a resource was found, false otherwise. + */ + static bool find_path(std::string& path, + const std::string& prefix = "", + const std::string& extension = ""); + + /** + * Get the path to a resource of a given name and open it if a resource + * was found. + * \param path The name of the resource to find. Upon successful + * return, this is changed to an absolute path to the resource. + * \param prefix A colon-separated list of subdirectories to search. + * \param extension A colon-separated list of possible extensions. + * \param mode The open mode. + * \return The FILE* if the resource was found, 0 otherwise. + */ + static FILE* open_file(std::string& path, + const std::string& prefix = "", + const std::string& extension = "", + const std::string& mode = "rb"); + + +private: + + static std::vector search_paths_; +}; + + +} // namespace moof + +#endif // _MOOF_RESOURCE_HH_ +