• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            文件系統的功能:
            1.資源包裹
            2.提供資源載入速度
            3.資源加密

            在蓋莫游戲引擎中
            文件系統由讀文件,寫文件,XML序列化對象,ConfigFile構成
            文件系統的接口如下:
            1.讀文件
            ////////////////////////////////////////////////////////////
            /// 定義讀2進制文件抽象基類
            ////////////////////////////////////////////////////////////
            class GAPI ReadFile: public Object
            {
            public:
                
            ////////////////////////////////////////////////////////
                
            /// 讀文件構造函數,析構函數
                
            ////////////////////////////////////////////////////////
                ReadFile();
                
            virtual ~ReadFile();

                
            ////////////////////////////////////////////////////////
                
            ///讀取文件數據
                
            ////////////////////////////////////////////////////////
                virtual uint Read(void* buf,uint size,uint number = 1=0;

                
            ////////////////////////////////////////////////////////
                
            ///獲取文件長度
                
            ////////////////////////////////////////////////////////
                virtual uint64 GetSize()const=0;

                
            ////////////////////////////////////////////////////////
                
            ///文件定位
                
            ////////////////////////////////////////////////////////
                virtual bool Seek(long offset,FILE_SEEK_MODE mode = FILE_SEEK_MODE_CURRENT) = 0;

                
            ////////////////////////////////////////////////////////
                
            ///獲取當前游標位置
                
            ////////////////////////////////////////////////////////
                virtual uint64 Tell()const = 0;

                
            ////////////////////////////////////////////////////////
                
            /// 獲取文件名
                
            ////////////////////////////////////////////////////////
                virtual engine_string GetFileName()const = 0;

                
            ////////////////////////////////////////////////////////
                
            ///合法性檢查
                
            ////////////////////////////////////////////////////////
                virtual bool IsValid()const = 0;
            private:
                DECLARE_OBJECT(ReadFile)
            };

            2.WriteFile
            ////////////////////////////////////////////////////////////
            /// 定義讀2進制文件抽象基類
            ////////////////////////////////////////////////////////////
            class GAPI WriteFile : public Object
            {
            public:
                
            ////////////////////////////////////////////////////////
                
            /// 寫文件構造函數,析構函數
                
            ////////////////////////////////////////////////////////
                WriteFile();
                
            virtual ~WriteFile();

                
            ////////////////////////////////////////////////////////
                
            ///寫數據
                
            ////////////////////////////////////////////////////////
                virtual uint Write(const void* buf,uint size,uint number = 1= 0;

                
            ////////////////////////////////////////////////////////
                
            ///文件定位
                
            ////////////////////////////////////////////////////////
                virtual bool Seek(long position,FILE_SEEK_MODE mode = FILE_SEEK_MODE_CURRENT) = 0;

                
            ////////////////////////////////////////////////////////
                
            ///獲取當前游標位置
                
            ////////////////////////////////////////////////////////
                virtual uint64 Tell()const = 0;

                
            ////////////////////////////////////////////////////////
                
            /// 獲取文件名
                
            ////////////////////////////////////////////////////////
                virtual engine_string GetFileName()const = 0;

                
            ////////////////////////////////////////////////////////
                
            ///合法性檢查
                
            ////////////////////////////////////////////////////////
                virtual bool IsValid()const = 0;
            private:
                DECLARE_OBJECT(WriteFile)
            };
            3.ConfigFile.
            ////////////////////////////////////////////////////////////
            /// 定義解析ini文件對象
            ////////////////////////////////////////////////////////////
            class GAPI ConfigFile
            {
            public:
                
            ////////////////////////////////////////////////////////
                
            /// 定義搜索的前置條件
                
            ////////////////////////////////////////////////////////
                template<class Pair>
                
            class StrPairEq : public std::binary_function<Pair,std::string,bool>
                {
                
            public:
                    
            bool operator()(const Pair& lhs,const std::string& rhs)const;
                };

                typedef std::pair
            <std::string,std::string> Variable;
                typedef std::list
            < Variable > Section;
                typedef std::pair
            < std::string, Section > NamedSection;
                typedef std::list
            < NamedSection > Layout;

            public:
                
            ////////////////////////////////////////////////////////
                
            /// 構造函數和析構函數
                
            ////////////////////////////////////////////////////////
                ConfigFile();
                ConfigFile(
            const std::string& filename);
                
            ~ConfigFile();
            public:
                
            ////////////////////////////////////////////////////////
                
            /// 打開指定文件
                
            ////////////////////////////////////////////////////////
                bool Open(const std::string& filename);

                
            ////////////////////////////////////////////////////////
                
            /// 把配置文件數據寫入磁盤
                
            ////////////////////////////////////////////////////////
                void Flush();

                
            ////////////////////////////////////////////////////////
                
            /// 關閉配置文件
                
            ////////////////////////////////////////////////////////
                void Close();

                
            ////////////////////////////////////////////////////////
                
            /// 寫(讀)數據的函數(不可使用于UDT數據)
                
            ////////////////////////////////////////////////////////
                template<class VarType>
                
            void SetVariable(const std::string& sec,const std::string& var,VarType value)
                {
                    std::
            string sec_brac(BracketString(sec));
                    Layout::iterator sec_iter;
                    Section::iterator var_iter;
                    std::ostringstream ss;
                    
            //! 寫數據到字符串
                    ss << value;

                    
            //! 檢索段
                    sec_iter = std::find_if(layout.begin(),layout.end(),std::bind2nd(StrPairEq<NamedSection>(),sec_brac));

                    
            //! 如果段不存在則增加之
                    if(sec_iter == layout.end())
                    {
                        layout.push_back(NamedSection(sec_brac, Section()));
                        sec_iter 
            = std::find_if(layout.begin(),layout.end(),std::bind2nd(StrPairEq<NamedSection>(),sec_brac));
                    }

                    
            //! 變量檢索
                    var_iter = std::find_if(sec_iter->second.begin(),sec_iter->second.end(),std::bind2nd(StrPairEq<Variable>(), var) );

                    
            //! 寫數據
                    if(var_iter == sec_iter->second.end())
                    {
                        sec_iter
            ->second.push_back(Variable(var, ss.str()));
                    }
                    
            else
                    {
                        var_iter
            ->second = ss.str();
                    }
                }

                template
            <class VarType>
                VarType GetVariable(
            const std::string& sec,const std::string& var,VarType defval)const
                {
                    std::
            string sec_brac(BracketString(sec));
                    std::stringstream ss;
                    VarType ret(defval);
                    Layout::const_iterator sec_iter;
                    Section::const_iterator var_iter;
                    sec_iter 
            = std::find_if(layout.begin(),layout.end(),std::bind2nd(StrPairEq<NamedSection>(),sec_brac));
                    
            if(sec_iter != layout.end())
                    {
                        var_iter 
            = std::find_if(sec_iter->second.begin(),sec_iter->second.end(),std::bind2nd(StrPairEq<Variable>(),var));
                        
            if(var_iter != sec_iter->second.end())
                        {
                            ss.str(var_iter
            ->second);
                            ss 
            >> ret;
                        }
                    }
                    
            return ret;
                }

                
            ////////////////////////////////////////////////////////
                
            /// 獲取配置文件有多少個塊
                
            ////////////////////////////////////////////////////////
                uint GetSectionNumber(){return layout.size();}

                
            ////////////////////////////////////////////////////////
                
            /// 檢索是否存在給定塊(塊,鍵)
                
            ////////////////////////////////////////////////////////
                bool HasSectionName(const std::string &section)
                {
                    Layout::iterator sec_iter;
                    sec_iter 
            = std::find_if(layout.begin(),layout.end(),std::bind2nd(StrPairEq<NamedSection>(),section));
                    
            return (sec_iter != layout.end());
                }
                
            bool HasKeyName(const std::string &section,const std::string &key)
                {
                    
            if(HasSectionName(section) == false)
                        
            return false;
                    Layout::iterator sec_iter;
                    sec_iter 
            = std::find_if(layout.begin(),layout.end(),std::bind2nd(StrPairEq<NamedSection>(),section));
                    Section::iterator var_iter 
            = std::find_if(sec_iter->second.begin(),sec_iter->second.end(),std::bind2nd(StrPairEq<Variable>(),key));
                    
            return (var_iter != sec_iter->second.end());
                }
            private:
                
            static std::string CleanString(const std::string& str);
                
            static std::string BracketString(const std::string& str);
            private:
                Layout      layout;
                std::
            string filename;
            };

            template
            <class Pair>
            bool ConfigFile::StrPairEq<Pair>::operator()(const Pair& lhs, const std::string& rhs)const
            {
                
            return ConfigFile::CleanString(lhs.first) == ConfigFile::CleanString(rhs);
            }
            4.FIleSYstem's Core
            ////////////////////////////////////////////////////////
            /// 定義引擎文件系統
            ////////////////////////////////////////////////////////
            class GAPI FileSystem
            {
            public:
                
            ////////////////////////////////////////////////////
                
            /// 獲取工作目錄
                
            ////////////////////////////////////////////////////
                engine_string GetWorkDir()const;

                
            ////////////////////////////////////////////////////
                
            /// 獲取用戶目錄
                
            ////////////////////////////////////////////////////
                engine_string GetUserDir()const;
            public:
                
            ////////////////////////////////////////////////////
                
            /// 注冊,反注冊資源包文件
                
            ////////////////////////////////////////////////////
                bool RegisterPackage(const engine_string& package);
                
            bool UnRegisterPackage(const engine_string& package);
                
            ////////////////////////////////////////////////////
                
            /// 獲取文件系統注冊資源包列表
                
            ////////////////////////////////////////////////////
                void GetPackageList(std::vector<engine_string> &packages);
            public:
                
            ////////////////////////////////////////////////////
                
            /// 檢測給定目錄是否為文件目錄
                
            ////////////////////////////////////////////////////
                bool IsDirectory(const engine_string& dir);

                
            ////////////////////////////////////////////////////
                
            /// 生成新的硬盤目錄
                
            ////////////////////////////////////////////////////
                bool CreateDirectory(const engine_string& dir);

                
            ////////////////////////////////////////////////////
                
            /// 刪除一個文件或者一個目錄(如果是目錄必須確保它是空的)
                
            ////////////////////////////////////////////////////
                bool DeleteFile(const engine_string& file);

                
            ////////////////////////////////////////////////////
                
            /// 檢測給定文件是否存在
                
            ////////////////////////////////////////////////////
                bool IsExist(const engine_string &filename);

                
            ////////////////////////////////////////////////////
                
            /// 獲取給定文件夾下的文件列表(返回1為硬盤文件列表,0為資源包文件列表)
                
            ////////////////////////////////////////////////////
                short GetFileList(const engine_string& dir,std::vector<engine_string> &filelist);

                
            ////////////////////////////////////////////////////
                
            /// 獲取給定文件后綴(比如main.cpp返回.cpp)
                
            ////////////////////////////////////////////////////
                engine_string GetFileExtension(const engine_string &file)const;

                
            ////////////////////////////////////////////////////////
                
            ///文件的創建
                
            ////////////////////////////////////////////////////////
                RefPtr<WriteFile> GetWrite(const engine_string& filename);

                
            ////////////////////////////////////////////////////////
                
            ///文件的打開
                
            ////////////////////////////////////////////////////////
                RefPtr<ReadFile> GetRead(const engine_string& filename);
            private:
                FileSystemImpl  
            *impl;
                DEFINE_SINGLETON(FileSystem);
            };

            可以看出文件系統提供的功能有
            獲取用戶目錄
            獲取當前程序目錄
            設置資源包
            獲取給定目錄下文件列表(資源包文件,硬盤文件)
            以及打開給定文件等
            簡單的測試例子如下:
                core::ConfigFile config;
                config.Open(
            "gaimosoft.ini");
                config.SetVariable
            <int>(std::string("block"),std::string("size"),1024);
                config.SetVariable
            <double>(std::string("block"),std::string("rand"),0.32);
                config.SetVariable
            <std::string>(std::string("name"),std::string("name"),std::string("gaimosoft"));
                
            double rand = config.GetVariable(std::string("block"),std::string("rand"),-1.0f);
                std::
            string name = config.GetVariable(std::string("name"),std::string("name"),std::string("mysoft"));
                std::cout
            <<name<<std::endl;
                name 
            = config.GetVariable(std::string("name"),std::string("address"),std::string("mysoft"));
                std::cout
            <<name<<std::endl;
                config.Close();

                std::cout
            <<GLOBAL_FILESYSTEM_PTR->RegisterPackage("font1.zip")<<endl;
                core::RefPtr
            <core::ReadFile> file = GLOBAL_FILESYSTEM_PTR->GetRead("main.o");
                
            if(file)
                    std::cout
            <<"file size is:"<<file->GetSize()<<std::endl;
                
            else
                    std::cout
            <<"not find file"<<std::endl;
                file
            ->Drop();
                std::cout
            <<GLOBAL_FILESYSTEM_PTR->DeleteFile("1.font")<<std::endl;
            我一直在努力ing.
            posted on 2010-08-21 16:26 ccsdu2009 閱讀(1599) 評論(2)  編輯 收藏 引用 所屬分類: Game引擎
            Comments
             
            久久国产精品一国产精品金尊| 丁香久久婷婷国产午夜视频| 中文无码久久精品| 欧美va久久久噜噜噜久久| 久久天天躁狠狠躁夜夜躁2O2O| AV无码久久久久不卡蜜桃| 国产精品无码久久久久| 模特私拍国产精品久久| 国产精品美女久久久m| 久久精品无码一区二区三区免费| 久久亚洲精品成人无码网站 | 久久精品国产WWW456C0M| 亚洲精品视频久久久| 国产韩国精品一区二区三区久久| 久久亚洲色一区二区三区| 久久综合综合久久狠狠狠97色88| 无码八A片人妻少妇久久| 一本一道久久精品综合 | 久久亚洲精品视频| 久久亚洲精品无码VA大香大香| 久久九九有精品国产23百花影院| 久久精品国产亚洲av麻豆图片 | 亚洲国产精品久久久天堂| 精品人妻伦九区久久AAA片69| 熟妇人妻久久中文字幕| 偷偷做久久久久网站| 日日狠狠久久偷偷色综合0| 精品久久久久一区二区三区| 久久免费线看线看| 日韩欧美亚洲综合久久影院d3| 天天爽天天狠久久久综合麻豆| 狠狠色婷婷久久一区二区| 无码人妻少妇久久中文字幕| 久久久久久无码国产精品中文字幕| 国产亚洲成人久久| AAA级久久久精品无码区| 品成人欧美大片久久国产欧美| 欧美日韩中文字幕久久伊人| 日韩亚洲欧美久久久www综合网 | 国产∨亚洲V天堂无码久久久| 麻豆AV一区二区三区久久 |