1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
//
// CScriptFile
//
// This class encapsulates a FILE pointer in a reference counted class for
// use within AngelScript.
//
#ifndef SCRIPTFILE_H
#define SCRIPTFILE_H
//---------------------------
// Compilation settings
//
// Set this flag to turn on/off write support
// 0 = off
// 1 = on
#ifndef AS_WRITE_OPS
#define AS_WRITE_OPS 1
#endif
//---------------------------
// Declaration
//
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include <angelscript.h>
#endif
#include <string>
#include <stdio.h>
BEGIN_AS_NAMESPACE
class CScriptFile
{
public:
CScriptFile();
void AddRef() const;
void Release() const;
// TODO: Implement the "r+", "w+" and "a+" modes
// mode = "r" -> open the file for reading
// "w" -> open the file for writing (overwrites existing file)
// "a" -> open the file for appending
int Open(const std::string &filename, const std::string &mode);
int Close();
int GetSize() const;
bool IsEOF() const;
// Reading
std::string ReadString(unsigned int length);
std::string ReadLine();
asINT64 ReadInt(asUINT bytes);
asQWORD ReadUInt(asUINT bytes);
float ReadFloat();
double ReadDouble();
// Writing
int WriteString(const std::string &str);
int WriteInt(asINT64 v, asUINT bytes);
int WriteUInt(asQWORD v, asUINT bytes);
int WriteFloat(float v);
int WriteDouble(double v);
// Cursor
int GetPos() const;
int SetPos(int pos);
int MovePos(int delta);
// Big-endian = most significant byte first
bool mostSignificantByteFirst;
protected:
~CScriptFile();
mutable int refCount;
FILE *file;
};
// This function will determine the configuration of the engine
// and use one of the two functions below to register the file type
void RegisterScriptFile(asIScriptEngine *engine);
// Call this function to register the file type
// using native calling conventions
void RegisterScriptFile_Native(asIScriptEngine *engine);
// Use this one instead if native calling conventions
// are not supported on the target platform
void RegisterScriptFile_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
|