shark_32 发表于 2011-11-16 09:15:38

fstream类Unicode化

有没有谁也有兴趣一起做一个支持Unicode的fstream类?
技术上不算很牛,不过还是很实用的

shark_32 发表于 2011-11-16 10:20:17

我现在想到的架构:
class TTextFile
{
private:
/*****************************************
        硬件相关,返回true为操作成功
******************************************/

        virtual bool        GetByte(char& Byte)=0; // 返回false按文件结尾论处
        virtual bool        PutByte(char& Byte)=0; // 返回false按空间不足论处


        virtual bool        OpenFile(wchar_t* FileName,char Mode)=0; // 返回false代表打开失败,可以用GetLastError查询
        virtual bool        SetWritePoint(unsigned int n)=0; // 输入的是第几个字符,譬如,ASCII文件是第n 个字节,UTF16文件是第(n+1)*2 个字节
        virtual bool        SetReadPoint(unsigned int n)=0; // 同上
       
       

        enum{NotOpen,Eof,ASCII,UTF16BigEndian,UTF16LittleEndian} State;
public:
        unsigned int CodePage;

        TTextFile& open(wchar_t* FileName,wchar_t mode);
        TTextFile& operator>>(wchar_t&);
        TTextFile& operator>>(char&);
        TTextFile& operator>>(wchar_t*);
        TTextFile& operator>>(char*);
       
        TTextFile& operator<<(wchar_t&);
        TTextFile& operator<<(char&);
        TTextFile& operator<<(wchar_t*);
        TTextFile& operator<<(char*);

        unsigned int getline(char* Buffer,unsigned int BufferSize);
        unsigned int getline(wchar_t* Buffer,unsigned int BufferSize);
       
        TTextFile&        seekg(unsigned int);
        TTextFile&        seekp(unsigned int);

        bool        eof(){return (State==Eof || State==NotOpen);}
        operator bool(){return eof();}

        TTextFile(wchar_t* FileName):State(NotOpen),File(0){open(FileName);}
        TTextFile():State(NotOpen){}
        ~TTextFile();
};
页: [1]
查看完整版本: fstream类Unicode化