tcuResource.hpp revision 3c827367444ee418f129b2c238299f49d3264554
1#ifndef _TCURESOURCE_HPP 2#define _TCURESOURCE_HPP 3/*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 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 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 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. 20 * 21 *//*! 22 * \file 23 * \brief Resource system. 24 *//*--------------------------------------------------------------------*/ 25 26#include "tcuDefs.hpp" 27 28#include <string> 29 30// \todo [2010-07-31 pyry] Move Archive and File* to separate files 31 32namespace tcu 33{ 34 35/*--------------------------------------------------------------------*//*! 36 * \brief Resource object 37 * 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. 41 * 42 * Resource objects are requested from Archive object provided by Platform. 43 * The user is responsible of disposing the objects afterwards. 44 *//*--------------------------------------------------------------------*/ 45class Resource 46{ 47public: 48 virtual ~Resource (void) {} 49 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; 54 55 const std::string& getName (void) const { return m_name; } 56 57protected: 58 Resource (const std::string& name) : m_name(name) {} 59 60private: 61 std::string m_name; 62}; 63 64/*--------------------------------------------------------------------*//*! 65 * \brief Abstract resource archive 66 *//*--------------------------------------------------------------------*/ 67class Archive 68{ 69public: 70 virtual ~Archive (void) {} 71 72 /*--------------------------------------------------------------------*//*! 73 * \brief Open resource 74 * 75 * Throws resource error if no resource with given name exists. 76 * 77 * Resource object must be deleted after use 78 * 79 * \param name Resource path 80 * \return Resource object 81 *//*--------------------------------------------------------------------*/ 82 virtual Resource* getResource (const char* name) const = 0; 83 84protected: 85 Archive () {} 86}; 87 88/*--------------------------------------------------------------------*//*! 89 * \brief Directory-based archive implementation 90 *//*--------------------------------------------------------------------*/ 91class DirArchive : public Archive 92{ 93public: 94 DirArchive (const char* path); 95 ~DirArchive (void); 96 97 Resource* getResource (const char* name) const; 98 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; } 102 103private: 104 std::string m_path; 105 106}; 107 108class FileResource : public Resource 109{ 110public: 111 FileResource (const char* filename); 112 ~FileResource (void); 113 114 void read (deUint8* dst, int numBytes); 115 int getSize (void) const; 116 int getPosition (void) const; 117 void setPosition (int position); 118 119private: 120 FileResource (const FileResource& other); 121 FileResource& operator= (const FileResource& other); 122 123 FILE* m_file; 124}; 125 126class ResourcePrefix : public Archive 127{ 128public: 129 ResourcePrefix (const Archive& archive, const char* prefix); 130 virtual ~ResourcePrefix (void) {} 131 132 virtual Resource* getResource (const char* name) const; 133 134private: 135 const Archive& m_archive; 136 std::string m_prefix; 137}; 138 139} // tcu 140 141#endif // _TCURESOURCE_HPP 142