Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_INPUTOUTPUT_FILE_H__
00009 #define __SP_INPUTOUTPUT_FILE_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spInputOutputString.hpp"
00014 #include "Base/spDimensionVector3D.hpp"
00015 #include "Base/spDimensionQuaternion.hpp"
00016 #include "Base/spDimensionMatrix4.hpp"
00017 #include "Base/spMaterialColor.hpp"
00018
00019 #include <cstdlib>
00020 #include <sstream>
00021 #include <string>
00022 #include <cstdio>
00023
00024
00025 namespace sp
00026 {
00027 namespace io
00028 {
00029
00030
00032 enum EFileSeekTypes
00033 {
00034 FILEPOS_BEGIN = SEEK_SET,
00035 FILEPOS_CURRENT = SEEK_CUR,
00036 FILEPOS_END = SEEK_END
00037 };
00038
00040 enum EFilePermission
00041 {
00042 FILE_UNDEFINED,
00043 FILE_READ,
00044 FILE_WRITE,
00045 FILE_WRITE_APPEND,
00046 FILE_READWRITE,
00047 FILE_READWRITE_APPEND,
00048 };
00049
00051 enum EFileTypes
00052 {
00053 FILE_PHYSICAL,
00054 FILE_VIRTUAL,
00055 FILE_ASSET,
00056 };
00057
00058
00060 class SP_EXPORT File
00061 {
00062
00063 public:
00064
00065 virtual ~File();
00066
00067
00068
00075 virtual bool open(const io::stringc &Filename, const EFilePermission Permission = FILE_READWRITE) = 0;
00076
00078 virtual void close() = 0;
00079
00080
00081
00083 virtual s32 writeString(const stringc &Str, u32 Count = 1);
00084
00086 virtual s32 writeStringN(const stringc &Str, u32 Count = 1);
00087
00089 virtual s32 writeStringC(const stringc &Str, u32 Count = 1);
00090
00092 virtual s32 writeStringData(const stringc &Str, u32 Count = 1);
00093
00094
00095
00097 virtual stringc readString(s32 Length) const;
00098
00100 virtual stringc readString(bool BreakPrompt = false) const;
00101
00103 virtual stringc readStringC() const;
00104
00106 virtual stringc readStringData() const;
00107
00108
00109
00110 virtual s32 writeBuffer(const void* Buffer, u32 Size, u32 Count = 1) = 0;
00111 virtual s32 readBuffer(void* Buffer, u32 Size, u32 Count = 1) const = 0;
00112
00113 virtual void writeColor(const video::color &Color);
00114 virtual video::color readColor() const;
00115
00116 virtual void setSeek(s32 Pos, const EFileSeekTypes PosType = FILEPOS_BEGIN) = 0;
00117 virtual s32 getSeek() const = 0;
00118
00120 virtual bool isEOF() const = 0;
00121
00123 virtual u32 getSize() const = 0;
00124
00131 virtual void* getHandle() = 0;
00132
00134 virtual bool opened() const = 0;
00135
00136
00137
00138 inline void setFilename(const io::stringc &Filename)
00139 {
00140 Filename_ = Filename;
00141 }
00142 inline stringc getFilename() const
00143 {
00144 return Filename_;
00145 }
00146
00148 inline EFileTypes getType() const
00149 {
00150 return Type_;
00151 }
00153 inline EFilePermission getPermission() const
00154 {
00155 return Permission_;
00156 }
00157
00158 inline bool hasReadAccess() const
00159 {
00160 return Permission_ == FILE_READ || Permission_ == FILE_READWRITE || Permission_ == FILE_READWRITE_APPEND;
00161 }
00162 inline bool hasWriteAccess() const
00163 {
00164 return Permission_ == FILE_WRITE || Permission_ == FILE_WRITE_APPEND || Permission_ == FILE_READWRITE || Permission_ == FILE_READWRITE_APPEND;
00165 }
00166
00168 inline void ignore(s32 Count)
00169 {
00170 setSeek(Count, FILEPOS_CURRENT);
00171 }
00172
00173
00174
00175 template <typename T> s32 writeValue(const T &Value, u32 Count = 1)
00176 {
00177 return writeBuffer(&Value, sizeof(T), Count);
00178 }
00179 template <typename T> T readValue() const
00180 {
00181 T Value;
00182 readBuffer(&Value, sizeof(Value));
00183 return Value;
00184 }
00185
00186 template <typename T> void writeVector(const dim::vector3d<T> &Vec)
00187 {
00188 writeBuffer(&Vec.X, sizeof(dim::vector3d<T>));
00189 }
00190 template <typename T> dim::vector3d<T> readVector() const
00191 {
00192 dim::vector3d<T> Vec;
00193 readBuffer(&Vec.X, sizeof(dim::vector3d<T>));
00194 return Vec;
00195 }
00196
00197 template <typename T> void writeMatrix(const dim::matrix4<T> &Mat)
00198 {
00199 writeBuffer(Mat.getArray(), sizeof(dim::matrix4<T>));
00200 }
00201 template <typename T> dim::matrix4<T> readMatrix() const
00202 {
00203 dim::matrix4<T> Mat;
00204 readBuffer(&Mat[0], sizeof(dim::matrix4<T>));
00205 return Mat;
00206 }
00207
00208 inline void writeQuaternion(const dim::quaternion &Quat)
00209 {
00210 writeBuffer(&Quat.X, sizeof(dim::quaternion));
00211 }
00212 inline dim::quaternion readQuaternion() const
00213 {
00214 dim::quaternion Quat;
00215 readBuffer(&Quat.X, sizeof(dim::quaternion));
00216 return Quat;
00217 }
00218
00219 protected:
00220
00221 File(const EFileTypes Type);
00222
00223
00224
00225 stringc Filename_;
00226 EFileTypes Type_;
00227 EFilePermission Permission_;
00228
00229 };
00230
00231
00232 }
00233
00234 }
00235
00236
00237 #endif
00238
00239
00240
00241