From patchwork Wed Aug 10 13:58:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3375 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1131723F46 for ; Wed, 10 Aug 2011 13:58:26 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id CEFA7A1820C for ; Wed, 10 Aug 2011 13:58:25 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so813305qwb.11 for ; Wed, 10 Aug 2011 06:58:25 -0700 (PDT) Received: by 10.229.44.195 with SMTP id b3mr6488453qcf.7.1312984704253; Wed, 10 Aug 2011 06:58:24 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.190.71 with SMTP id dh7cs81761qcb; Wed, 10 Aug 2011 06:58:23 -0700 (PDT) Received: from mr.google.com ([10.216.82.205]) by 10.216.82.205 with SMTP id o55mr873808wee.64.1312984702685 (num_hops = 1); Wed, 10 Aug 2011 06:58:22 -0700 (PDT) Received: by 10.216.82.205 with SMTP id o55mr603962wee.64.1312984701690; Wed, 10 Aug 2011 06:58:21 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id h8si2509521wee.11.2011.08.10.06.58.21; Wed, 10 Aug 2011 06:58:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Qr9Ib-0004nj-1I for ; Wed, 10 Aug 2011 13:58:21 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 085912E8005 for ; Wed, 10 Aug 2011 13:58:21 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 120 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 120: Access resources in an abstract way using std::istream. Message-Id: <20110810135821.1453.71644.launchpad@loganberry.canonical.com> Date: Wed, 10 Aug 2011 13:58:21 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13636"; Instance="initZopeless config overlay" X-Launchpad-Hash: 25bf80beccfc04b459bc1825236bb982233f1a04 Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 120 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Wed 2011-08-10 16:56:41 +0300 message: Access resources in an abstract way using std::istream. modified: src/model.cpp src/shader-source.cpp src/texture.cpp src/util.cpp src/util.h --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'src/model.cpp' --- src/model.cpp 2011-07-19 13:42:53 +0000 +++ src/model.cpp 2011-08-10 13:52:04 +0000 @@ -25,9 +25,10 @@ #include "vec.h" #include "log.h" #include "options.h" +#include "util.h" -#include #include +#include #define read_or_fail(file, dst, size) do { \ file.read(reinterpret_cast((dst)), (size)); \ @@ -164,7 +165,9 @@ Log::debug("Loading model from 3ds file '%s'\n", filename.c_str()); - std::ifstream input_file(filename.c_str()); + const std::auto_ptr input_file_ptr(Util::get_resource(filename)); + std::istream& input_file(*input_file_ptr); + if (!input_file) { Log::error("Could not open 3ds file '%s'\n", filename.c_str()); return false; === modified file 'src/shader-source.cpp' --- src/shader-source.cpp 2011-07-28 08:44:31 +0000 +++ src/shader-source.cpp 2011-08-10 13:53:02 +0000 @@ -20,11 +20,13 @@ * Alexandros Frantzis (glmark2) */ -#include +#include +#include #include "shader-source.h" #include "log.h" #include "vec.h" +#include "util.h" /** * Loads the contents of a file into a string. @@ -35,8 +37,9 @@ bool ShaderSource::load_file(const std::string& filename, std::string& str) { - using std::ifstream; - ifstream inputFile(filename.c_str()); + std::auto_ptr is_ptr(Util::get_resource(filename)); + std::istream& inputFile(*is_ptr); + if (!inputFile) { Log::error("Failed to open \"%s\"\n", filename.c_str()); === modified file 'src/texture.cpp' --- src/texture.cpp 2011-07-14 17:23:51 +0000 +++ src/texture.cpp 2011-08-10 13:52:40 +0000 @@ -23,24 +23,21 @@ */ #include "texture.h" #include "log.h" +#include "util.h" #include #include +#include class PNGState { public: PNGState() : - fp_(0), png_(0), info_(0), rows_(0) {} ~PNGState() { - if (fp_) - { - fclose(fp_); - } if (png_) { png_destroy_read_struct(&png_, &info_, 0); @@ -55,8 +52,8 @@ Log::debug("Reading PNG file %s\n", filename.c_str()); - fp_ = fopen(filename.c_str(), "rb"); - if (!fp_) { + const std::auto_ptr is_ptr(Util::get_resource(filename)); + if (!(*is_ptr)) { Log::error("Cannot open file %s!\n", filename.c_str()); return false; } @@ -81,7 +78,7 @@ } /* Read the image information and data */ - png_init_io(png_, fp_); + png_set_read_fn(png_, reinterpret_cast(is_ptr.get()), png_read_fn); png_read_png(png_, info_, png_transforms, 0); @@ -101,7 +98,11 @@ } const unsigned char* row(unsigned int idx) const { return rows_[idx]; } private: - FILE* fp_; + static void png_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) + { + std::istream *is = reinterpret_cast(png_get_io_ptr(png_ptr)); + is->read(reinterpret_cast(data), length); + } png_structp png_; png_infop info_; png_bytepp rows_; === modified file 'src/util.cpp' --- src/util.cpp 2011-08-09 10:34:49 +0000 +++ src/util.cpp 2011-08-10 13:32:04 +0000 @@ -22,6 +22,7 @@ */ #include +#include #include "util.h" @@ -42,3 +43,10 @@ elems.push_back(item); } +std::istream * +Util::get_resource(const std::string &path) +{ + std::ifstream *ifs = new std::ifstream(path.c_str()); + + return static_cast(ifs); +} === modified file 'src/util.h' --- src/util.h 2011-08-09 10:34:49 +0000 +++ src/util.h 2011-08-10 13:32:04 +0000 @@ -26,9 +26,11 @@ #include #include +#include struct Util { static void split(const std::string &s, char delim, std::vector &elems); + static std::istream *get_resource(const std::string &path); }; #endif /* UTIL_H */