From patchwork Tue May 22 10:33:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 8860 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 B544A23F07 for ; Tue, 22 May 2012 10:33:16 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 6DE8BA18AF8 for ; Tue, 22 May 2012 10:33:16 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so6370030yen.11 for ; Tue, 22 May 2012 03:33:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=dkImV3vu9DocyL086U/6wF9MPoBlZxp6tHd5yHnGnUU=; b=QoM5xwM5g6d1R3fXmWNf4xuTawHqf0QQ7GTw20ZWTU/jQQLz4vPEvCaSDMiuLaye1K C+XrAZJTj6/bA7KwJBkqgRkiMX/iGuYOCp7w/VGKcnTuY4baS8dwx5Gj4HLB3k7XxmQ7 stObozip15ff3FDFS1Kqzt25SmumtGIAmJ++bVaZlg6yBumJ5eZZRWrKzloU4yroF8UQ 2WhOdLb0FCpMRHItjmWlKQFuhJmbObBPXV5XdoFoRxXI1U9M9IgOj8ofcE+9FO2va5sk Ik6yL7x/qZbBVDWSP4DyFTAyjxgkUFi/H2XFjbd1YPhXbKRf61U6QSSbMlWlOdP3eKZP 05mA== Received: by 10.50.163.99 with SMTP id yh3mr8846348igb.53.1337682795950; Tue, 22 May 2012 03:33:15 -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.231.35.72 with SMTP id o8csp355663ibd; Tue, 22 May 2012 03:33:14 -0700 (PDT) Received: by 10.180.83.168 with SMTP id r8mr33628946wiy.22.1337682793651; Tue, 22 May 2012 03:33:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id l2si14372610wiw.41.2012.05.22.03.33.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 May 2012 03:33:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1SWmOv-0001Gu-1l for ; Tue, 22 May 2012 10:33:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id F209FE03F1 for ; Tue, 22 May 2012 10:33:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glcompbench X-Launchpad-Branch: ~glcompbench-dev/glcompbench/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 85 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glcompbench-dev/glcompbench/trunk] Rev 85: libmatrix: Update to release 2012.05. Message-Id: <20120522103312.24737.71039.launchpad@ackee.canonical.com> Date: Tue, 22 May 2012 10:33:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15275"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 3a07783672ec8f6469bc67b166f42a66fc24063a X-Gm-Message-State: ALoCoQnpeyl2J2EexO1auLhLTfZ0pNNWju0JPyFeH4zGFfCTimxfVw3LE87h2EVgmOjSoYimuwCm ------------------------------------------------------------ revno: 85 committer: Jesse Barker branch nick: trunk timestamp: Tue 2012-05-22 10:55:39 +0100 message: libmatrix: Update to release 2012.05. modified: src/libmatrix/Makefile src/libmatrix/util.cc src/libmatrix/util.h --- lp:glcompbench https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk You are subscribed to branch lp:glcompbench. To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription === modified file 'src/libmatrix/Makefile' --- src/libmatrix/Makefile 2012-01-26 19:36:28 +0000 +++ src/libmatrix/Makefile 2012-05-22 09:55:39 +0000 @@ -21,7 +21,7 @@ program.o: program.cc program.h mat.h vec.h log.o: log.cc log.h util.o: util.cc util.h -shader-source.o: shader-source.cc shader-source.h mat.h vec.h +shader-source.o: shader-source.cc shader-source.h mat.h vec.h util.h libmatrix.a : mat.o stack.h program.o log.o util.o shader-source.o $(AR) -r $@ $(LIBOBJS) === modified file 'src/libmatrix/util.cc' --- src/libmatrix/util.cc 2012-01-27 22:21:17 +0000 +++ src/libmatrix/util.cc 2012-05-22 09:55:39 +0000 @@ -22,21 +22,58 @@ #include "log.h" #include "util.h" -/** - * Splits a string using a delimiter - * - * @param s the string to split - * @param delim the delimitir to use - * @param elems the string vector to populate - */ +using std::string; +using std::vector; + void -Util::split(const std::string &s, char delim, std::vector &elems) +Util::split(const string& src, char delim, vector& elementVec, bool fuzzy) { - std::stringstream ss(s); - - std::string item; - while(std::getline(ss, item, delim)) - elems.push_back(item); + // Trivial rejection + if (src.empty()) + { + return; + } + + // Simple case: we want to enforce the value of 'delim' strictly + if (!fuzzy) + { + std::stringstream ss(src); + string item; + while(std::getline(ss, item, delim)) + elementVec.push_back(item); + return; + } + + // Fuzzy case: Initialize our delimiter string based upon the caller's plus + // a space to allow for more flexibility. + string delimiter(" "); + delimiter += delim; + // Starting index into the string of the first token (by definition, if + // we're parsing a string, there is at least one token). + string::size_type startPos(0); + // string::find_first_of() looks for any character in the string provided, + // it is not treated as a sub-string, so regardless of where the space or + // comma is or how many there are, the result is the same. + string str(src); + string::size_type endPos = str.find_first_of(delimiter); + while (endPos != string::npos) + { + // Push back the current element starting at startPos for + // (endPos - startPos) characters. std::string takes care of + // terminators, etc. + elementVec.push_back(string(str, startPos, endPos - startPos)); + // Index of the next element after any delimiter characters. Same + // caveat applies to find_first_not_of() that applies to + // find_first_of(); endPos tells it where to start the search. + string::size_type nextPos = str.find_first_not_of(delimiter, endPos); + // Erase the part of the string we've already parsed. + str = str.erase(startPos, nextPos - startPos); + // Look for the next delimiter. If there isn't one, we bail out. + endPos = str.find_first_of(delimiter); + } + // Regardless of whether we initially had one element or many, 'str' now + // only contains one. + elementVec.push_back(str); } uint64_t === modified file 'src/libmatrix/util.h' --- src/libmatrix/util.h 2012-01-27 22:21:17 +0000 +++ src/libmatrix/util.h 2012-05-22 09:55:39 +0000 @@ -24,10 +24,53 @@ #endif struct Util { - static void split(const std::string &s, char delim, std::vector &elems); + /** + * split() - Splits a string into elements using a provided delimiter + * + * @s: the string to split + * @delim: the delimiter to use + * @elems: the string vector to populate + * @fuzzy: (optional) enable/disable strict handling of @delim + * + * Using @delim to determine field boundaries, splits @s into separate + * string elements. These elements are returned in the string vector + * @elems. If @fuzzy is true, then the handling of @delim allows for + * spaces and multiple consecutive occurences of @delim in determining + * field boundaries. As long as @s is non-empty, there will be at least + * one element in @elems. + */ + static void split(const std::string &s, char delim, std::vector &elems, bool fuzzy = false); + /** + * get_timestamp_us() - Returns the current time in microseconds + */ static uint64_t get_timestamp_us(); + /** + * get_resource() - Gets an input filestream for a given file. + * + * @path: the path to the file + * + * Returns a pointer to an input stream, which must be deleted when no + * longer in use. + */ static std::istream *get_resource(const std::string &path); + /** + * list_files() - Get a list of the files in a given directory. + * + * @dirName: the directory path to be listed. + * @fileVec: the string vector to populate. + * + * Obtains a list of the files in @dirName, and returns them in the string + * vector @fileVec. + */ static void list_files(const std::string& dirName, std::vector& fileVec); + /** + * dispose_pointer_vector() - cleans up a vector of pointers + * + * @vec: vector of pointers to objects or plain-old-data + * + * Iterates across @vec and deletes the data pointed to by each of the + * elements. Clears the vector, resetting it for reuse. + */ template static void dispose_pointer_vector(std::vector &vec) { for (typename std::vector::const_iterator iter = vec.begin(); @@ -39,16 +82,25 @@ vec.clear(); } + /** + * toString() - Converts a string to a plain-old-data type. + * + * @asString: a string representation of plain-old-data. + */ template static T fromString(const std::string& asString) { std::stringstream ss(asString); - T retVal; + T retVal = T(); ss >> retVal; return retVal; } - + /** + * toString() - Converts a plain-old-data type to a string. + * + * @t: a simple value to be converted to a string + */ template static std::string toString(const T t) @@ -57,6 +109,13 @@ ss << t; return ss.str(); } + /** + * appname_from_path() - get the name of an executable from an absolute path + * + * @path: absolute path of the running application (argv[0]) + * + * Returns the last portion of @path (everything after the final '/'). + */ static std::string appname_from_path(const std::string& path);