Lazy writing instructions directly lay code
/* <Br/> * @ file filepath. HPP <br/> * Project Description: constructs a game engine. <br/> * file Description: Game File System <br/> * Applicable platform: windows/Lunix/unitx /.. <br/> * Author: ccsdu2004 <br/> * Email: ccsdu2004@yahoo.com.cn <br/> * URL: www.gaimo.net/Hi/csdn.net/ccsdu2004 <br/> * creation date: <br/> * modification date :.. <br/> */</P> <p> # ifndef g_util_filepath_hpp <br/> # define g_util_filepath_hpp </P> <p> # include <string> <br/> # include <set> <br/> # In Clude <vector> <br/> # include <boost/noncopyable. HPP> <br/> # include <boost/filesystem. HPP> </P> <p> using namespace STD; <br/> using namespace boost: filesystem; </P> <p> namespace G <br/> {<br/> namespace file <br/> {<br/> class _ declspec (dllexport) filepath: public noncopyable <br/>{< br/> Public: <br/> // The folder path <br/> filepath (string filepath); <br/> ~ Filepath () {}< br/> Public: <br/> inline void find_in_sub_path (bool flag = false) {subpath = flag;} <br/> // lie that: *. map3 *. wav... <br/> void set_suffix (const string & suffixs); <br/> void get_files (vector <string> & files); <br/> PRIVATE: <br/> void find (boost: filesystem: path P); <br/> PRIVATE: <br/> string filepath; <br/> bool subpath; <br/> vector <string> file; <br/> set <string> suffix; <br/> bool usesf; <br/> }; <br/>}</P> <p> # endif
# Include <boost/tokenizer. HPP>
# Include <boost/algorithm/string. HPP>
# Include <boost/filesystem/exception. HPP>
# Include "filepath. HPP"
Using namespace boost: algorithm;
Namespace g
{
Namespace File
{
Filepath: filepath (string _ filepath): filepath (_ filepath ),
Subpath (false ),
Usesf (false)
{}
Void filepath: set_suffix (const string & suffixs)
{
String temp (suffixs );
To_lower (temp );
Tokenizer <> SF (temp );
For (tokenizer <>:: iterator itr = SF. Begin (); itr! = SF. End (); ++ itr)
{
Suffix. insert (* itr );
}
Usesf = true;
}
Void filepath: get_files (vector <string> & files)
{
Boost: filesystem: path _ filepath (filepath, boost: filesystem: Native );
Find (_ filepath );
Files = file;
}
Void filepath: Find (boost: filesystem: path P)
{
Try
{
If (boost: filesystem: exists (p) = true)
{
Boost: filesystem: directory_iterator item_begin (P );
Boost: filesystem: directory_iterator item_end;
For (; item_begin! = Item_end; item_begin ++)
{
If (boost: filesystem: is_directory (* item_begin) = true & subpath = true)
{
// (* Item_begin)
// (* Itr)
Find (item_begin-> path ());
}
Else
{
String filename = item_begin-> leaf ();
If (usesf = true)
{
To_lower (filename );
Set <string >:: iterator itr = suffix. Begin ();
While (itr! = Suffix. End ())
{
If (ends_with (filename, * itr) = true)
File. push_back (filename );
Itr ++;
}
}
Else
{
File. push_back (filename );
}
}
}
}
}
Catch (boost: filesystem: filesystem_error E)
{
}
}
}
}