/
FastReader.cpp
128 lines (97 loc) · 3.46 KB
/
FastReader.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************************
* Ruthenium Engine *
* Copyright (c) 2013-2017 Stepanov Dmitriy aka mrDIMAS *
* *
* This file is part of Ruthenium Engine. *
* *
* Ruthenium Engine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* Ruthenium Engine is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with Ruthenium Engine. If not, see <http://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include "Precompiled.h"
#include "FastReader.h"
bool FastReader::IsEnded( ) {
return mCursor > mSize;
}
btQuaternion FastReader::GetQuaternion( ) {
float x = GetFloat( );
float y = GetFloat( );
float z = GetFloat( );
float w = GetFloat( );
return btQuaternion( x, y, z, w );
}
Vector2 FastReader::GetBareVector2( ) {
float x = GetFloat( );
float y = GetFloat( );
return Vector2( x, y );
}
Vector3 FastReader::GetBareVector( ) {
float x = GetFloat( );
float y = GetFloat( );
float z = GetFloat( );
return Vector3( x, y, z );
}
btVector3 FastReader::GetVector( ) {
float x = GetFloat( );
float y = GetFloat( );
float z = GetFloat( );
return btVector3( x, y, z );
}
std::string FastReader::GetString( ) {
string out;
for ( ; mData[ mCursor ] != '\0'; ++mCursor ) {
out += mData[ mCursor ];
}
if ( mData[ mCursor ] == '\0' ) {
++mCursor;
}
return out;
}
float FastReader::GetFloat( ) {
float value = *reinterpret_cast<float*>( mData + mCursor );
mCursor += sizeof( float );
return value;
}
unsigned char FastReader::GetByte( ) {
unsigned char value = mData[ mCursor ];
++mCursor;
return value;
}
unsigned short FastReader::GetShort( ) {
unsigned short value = *reinterpret_cast<unsigned short*>( mData + mCursor );
mCursor += sizeof( short );
return value;
}
int FastReader::GetInteger( ) {
int value = *reinterpret_cast<int *>( mData + mCursor );
mCursor += sizeof( int );
return value;
}
FastReader::~FastReader( ) {
delete[ ] mData;
}
bool FastReader::ReadFile( const string & fileName ) {
ifstream file( fileName, ios_base::binary );
if ( !file.good( ) ) {
return false;
}
file.seekg( 0, ios_base::end );
mSize = file.tellg( );
mData = new Byte[ mSize ];
file.seekg( 0, ios_base::beg );
file.read( reinterpret_cast<char*>( mData ), mSize );
file.close( );
return true;
}
FastReader::FastReader( ) : mSize( 0 ), mCursor( 0 ), mData( 0 ) {
}