File: MushFileFile.cpp

package info (click to toggle)
adanaxisgpl 1.2.5.dfsg.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, sid, stretch
  • size: 39,988 kB
  • sloc: ansic: 69,023; cpp: 65,175; ruby: 14,217; xml: 8,416; sh: 7,434; perl: 2,233; objc: 256; makefile: 154; yacc: 92
file content (265 lines) | stat: -rw-r--r-- 6,079 bytes parent folder | download | duplicates (2)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//%Header {
/*****************************************************************************
 *
 * File: src/MushFile/MushFileFile.cpp
 *
 * Author: Andy Southgate 2002-2007
 *
 * This file contains original work by Andy Southgate.  The author and his
 * employer (Mushware Limited) irrevocably waive all of their copyright rights
 * vested in this particular version of this file to the furthest extent
 * permitted.  The author and Mushware Limited also irrevocably waive any and
 * all of their intellectual property rights arising from said file and its
 * creation that would otherwise restrict the rights of any party to use and/or
 * distribute the use of, the techniques and methods used herein.  A written
 * waiver can be obtained via http://www.mushware.com/.
 *
 * This software carries NO WARRANTY of any kind.
 *
 ****************************************************************************/
//%Header } auyZAuHnB4Ph19/RkgE9ZA
/*
 * $Id: MushFileFile.cpp,v 1.4 2007/04/18 09:22:32 southa Exp $
 * $Log: MushFileFile.cpp,v $
 * Revision 1.4  2007/04/18 09:22:32  southa
 * Header and level fixes
 *
 * Revision 1.3  2006/11/07 11:08:54  southa
 * Texture loading from mushfiles
 *
 * Revision 1.2  2006/11/06 19:27:51  southa
 * Mushfile handling
 *
 * Revision 1.1  2006/11/06 12:56:32  southa
 * MushFile work
 *
 */

#include "MushFileFile.h"

#include "MushFileLibrary.h"

#include <cstring>

using namespace Mushware;
using namespace std;

std::string
MushFileFile::Name(void) const
{
    return m_filename.Name();
}

void
MushFileFile::OpenForRead(const std::string& inName)
{
    m_filename.NameSet(inName);
    m_filename.ResolveForRead();
    
    if (m_filename.SourceIsMush())
    {
        MushFileLibrary::Sgl().Load(m_data, m_filename.ResolvedName());
        m_seekPos = 0;
    }
    else if (m_filename.SourceIsFile())
    {
        
    }
}

Mushware::U8 *
MushFileFile::DataStart(void)
{
    if (!m_filename.SourceIsMush())
    {
        throw MushcoreFileFail(m_filename.Name(), "File is not in a mushfile");
    }

    return &m_data[0];
}

Mushware::tSize
MushFileFile::DataSize(void)
{
    if (!m_filename.SourceIsMush())
    {
        throw MushcoreFileFail(m_filename.Name(), "File is not in a mushfile");
    }
    return m_data.size();
}

Mushware::tSize
MushFileFile::DataRead(void *outData, Mushware::tSize inSize)
{
    tSize readSize = inSize;
    if (m_seekPos >= m_data.size())
    {
        readSize = 0;
    }
    else if (m_seekPos + readSize >= m_data.size())
    {
        readSize = m_data.size() - m_seekPos;
    }
    std::memcpy(outData, &m_data[m_seekPos], readSize);
    m_seekPos += readSize;
    
    return readSize;
}

void
MushFileFile::DataSeek(Mushware::tSize inSeekPos)
{
    m_seekPos = inSeekPos;
    if (m_seekPos >= m_data.size())
    {
        m_seekPos = m_data.size();
    }
}

std::string
MushFileFile::PlainFilename(void)
{
    if (!m_filename.SourceIsFile())
    {
        throw MushcoreFileFail(m_filename.Name(), "File is not a plain file");
    }
    return m_filename.ResolvedName();
}

Mushware::S32
MushFileFile::TIFFRead(void *inHandle, void *inData, Mushware::S32 inSize)
{
    MushFileFile *pFile = reinterpret_cast<MushFileFile *>(inHandle);
    return pFile->DataRead(inData, inSize);
}

Mushware::S32
MushFileFile::TIFFWrite(void *inHandle, void *inData, Mushware::S32 inSize)
{
    return 0; // Always fail
}

Mushware::U32
MushFileFile::TIFFSeek(void *inHandle, Mushware::U32 inOffset, int inFrom)
{
    MushFileFile *pFile = reinterpret_cast<MushFileFile *>(inHandle);
    tSize seekPos = 0;
    
    switch (inFrom)
    {
        case SEEK_SET:
            seekPos = inOffset;
            break;
            
        case SEEK_CUR:
            seekPos = inOffset + pFile->SeekPos();
            break;
            
        case SEEK_END:
            seekPos = pFile->DataSize() - inOffset;
            break;
            
        default:
            throw MushcoreRequestFail("Unknown seek type");
    }
    pFile->DataSeek(seekPos);
    
    return inOffset;
}

int
MushFileFile::TIFFClose(void *inHandle)
{
    return 0;
}

Mushware::U32
MushFileFile::TIFFSize(void *inHandle)
{
    MushFileFile *pFile = reinterpret_cast<MushFileFile *>(inHandle);
    return static_cast<S32>(pFile->DataSize());
}

//%outOfLineFunctions {

const char *MushFileFile::AutoName(void) const
{
    return "MushFileFile";
}

MushcoreVirtualObject *MushFileFile::AutoClone(void) const
{
    return new MushFileFile(*this);
}

MushcoreVirtualObject *MushFileFile::AutoCreate(void) const
{
    return new MushFileFile;
}

MushcoreVirtualObject *MushFileFile::AutoVirtualFactory(void)
{
    return new MushFileFile;
}
namespace
{
void AutoInstall(void)
{
    MushcoreFactory::Sgl().FactoryAdd("MushFileFile", MushFileFile::AutoVirtualFactory);
}
MushcoreInstaller AutoInstaller(AutoInstall);
} // end anonymous namespace
void
MushFileFile::AutoPrint(std::ostream& ioOut) const
{
    ioOut << "[";
    ioOut << "filename=" << m_filename << ", ";
    ioOut << "sourceType=" << m_sourceType << ", ";
    ioOut << "data=" << m_data << ", ";
    ioOut << "seekPos=" << m_seekPos;
    ioOut << "]";
}
bool
MushFileFile::AutoXMLDataProcess(MushcoreXMLIStream& ioIn, const std::string& inTagStr)
{
    if (inTagStr == "obj")
    {
        AutoInputPrologue(ioIn);
        ioIn >> *this;
        AutoInputEpilogue(ioIn);
    }
    else if (inTagStr == "filename")
    {
        ioIn >> m_filename;
    }
    else if (inTagStr == "sourceType")
    {
        ioIn >> m_sourceType;
    }
    else if (inTagStr == "data")
    {
        ioIn >> m_data;
    }
    else if (inTagStr == "seekPos")
    {
        ioIn >> m_seekPos;
    }
    else 
    {
        return false;
    }
    return true;
}
void
MushFileFile::AutoXMLPrint(MushcoreXMLOStream& ioOut) const
{
    ioOut.TagSet("filename");
    ioOut << m_filename;
    ioOut.TagSet("sourceType");
    ioOut << m_sourceType;
    ioOut.TagSet("data");
    ioOut << m_data;
    ioOut.TagSet("seekPos");
    ioOut << m_seekPos;
}
//%outOfLineFunctions } IxS6qDb/CxpIL3yB++2Wdg