1 #ifndef _TCURESOURCE_HPP
2 #define _TCURESOURCE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Resource system.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
30 // \todo [2010-07-31 pyry] Move Archive and File* to separate files
35 /*--------------------------------------------------------------------*//*!
36 * \brief Resource object
38 * Test framework uses abstraction for data access instead of using
39 * files directly to better support platforms where application resources
40 * are not available directly in the filesystem.
42 * Resource objects are requested from Archive object provided by Platform.
43 * The user is responsible of disposing the objects afterwards.
44 *//*--------------------------------------------------------------------*/
48 virtual ~Resource (void) {}
50 virtual void read (deUint8* dst, int numBytes) = 0;
51 virtual int getSize (void) const = 0;
52 virtual int getPosition (void) const = 0;
53 virtual void setPosition (int position) = 0;
55 const std::string& getName (void) const { return m_name; }
58 Resource (const std::string& name) : m_name(name) {}
64 /*--------------------------------------------------------------------*//*!
65 * \brief Abstract resource archive
66 *//*--------------------------------------------------------------------*/
70 virtual ~Archive (void) {}
72 /*--------------------------------------------------------------------*//*!
73 * \brief Open resource
75 * Throws resource error if no resource with given name exists.
77 * Resource object must be deleted after use
79 * \param name Resource path
80 * \return Resource object
81 *//*--------------------------------------------------------------------*/
82 virtual Resource* getResource (const char* name) const = 0;
88 /*--------------------------------------------------------------------*//*!
89 * \brief Directory-based archive implementation
90 *//*--------------------------------------------------------------------*/
91 class DirArchive : public Archive
94 DirArchive (const char* path);
97 Resource* getResource (const char* name) const;
99 // \note Assignment and copy allowed
100 DirArchive (const DirArchive& other) : Archive(), m_path(other.m_path) {}
101 DirArchive& operator= (const DirArchive& other) { m_path = other.m_path; return *this; }
108 class FileResource : public Resource
111 FileResource (const char* filename);
112 ~FileResource (void);
114 void read (deUint8* dst, int numBytes);
115 int getSize (void) const;
116 int getPosition (void) const;
117 void setPosition (int position);
120 FileResource (const FileResource& other);
121 FileResource& operator= (const FileResource& other);
126 class ResourcePrefix : public Archive
129 ResourcePrefix (const Archive& archive, const char* prefix);
130 virtual ~ResourcePrefix (void) {}
132 virtual Resource* getResource (const char* name) const;
135 const Archive& m_archive;
136 std::string m_prefix;
141 #endif // _TCURESOURCE_HPP