From patchwork Wed May 2 21:39:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 8366 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 8F46A23E1D for ; Wed, 2 May 2012 21:39:18 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 36BF3A187A5 for ; Wed, 2 May 2012 21:39:18 +0000 (UTC) Received: by yhpp61 with SMTP id p61so1520592yhp.11 for ; Wed, 02 May 2012 14:39:17 -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=P2D7hzZywERcEAdFNDfuiDMvVw5t/lotkjZjtqGEIAo=; b=MRjVvFgEHzhdSAecsK/x+KdoeubzfZ7UighInSv4lOIazsBtblGmgAAxN/ZBJdnBYz yD5Qd1MkPGM7qA9Jedr6Qvis25ZiBIMuRpJaEqHrgdntBHYGwrszM5nnd1kYY9qUWbKt Kf2CuHTocWqKyowO0VTe+g8Gq5L9dZh8W4qi6zlgqS+y9065QfiS8n1Xbt7LX26mal6z 3AS4Vb9RXY2aUXDx25NnjYH3C3p69gLoUW56OfN2MyQb4AZPitX/LikkeP5W/Pd8xHtZ +V8sOzmU98WW9ys8468xi9hvar3WWI73SDDru9yd3qhF734J9w6rd3i+mCMCduNRuTDs CkYw== Received: by 10.42.139.9 with SMTP id e9mr383188icu.43.1335994757541; Wed, 02 May 2012 14:39:17 -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.137.198 with SMTP id x6csp283357ibt; Wed, 2 May 2012 14:39:16 -0700 (PDT) Received: by 10.180.96.228 with SMTP id dv4mr13812505wib.14.1335994755750; Wed, 02 May 2012 14:39:15 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id h60si3571114wed.51.2012.05.02.14.39.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 May 2012 14:39:15 -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 1SPhGU-0000hm-Ki for ; Wed, 02 May 2012 21:39:14 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 929B7E028D for ; Wed, 2 May 2012 21:39:14 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: libmatrix X-Launchpad-Branch: ~jesse-barker/libmatrix/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 38 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~jesse-barker/libmatrix/trunk] Rev 38: Util: Update dependencies on util.h (shader-source). Make Util::split() support Message-Id: <20120502213914.17063.81695.launchpad@ackee.canonical.com> Date: Wed, 02 May 2012 21:39:14 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15185"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 3c7985a726b2a026070055b60b861cf394479f36 X-Gm-Message-State: ALoCoQkGImGtc2JZaWmPPosX7kH2PbeKNUAsV96zXL6maNqCL4ca8OaFFxJMcHXuu5pxPTIJE7gu ------------------------------------------------------------ revno: 38 committer: Jesse Barker branch nick: trunk timestamp: Wed 2012-05-02 14:36:04 -0700 message: Util: Update dependencies on util.h (shader-source). Make Util::split() support both explicit and "fuzzy" delimiters when parsing a string. Add API documentation for all of Util. modified: Makefile util.cc util.h --- lp:libmatrix https://code.launchpad.net/~jesse-barker/libmatrix/trunk You are subscribed to branch lp:libmatrix. To unsubscribe from this branch go to https://code.launchpad.net/~jesse-barker/libmatrix/trunk/+edit-subscription === modified file 'Makefile' --- Makefile 2012-01-23 19:18:34 +0000 +++ Makefile 2012-05-02 21:36:04 +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 'util.cc' --- util.cc 2012-05-01 22:58:28 +0000 +++ util.cc 2012-05-02 21:36:04 +0000 @@ -26,14 +26,26 @@ using std::vector; void -Util::split(const string& src, char delim, vector& elementVec) +Util::split(const string& src, char delim, vector& elementVec, bool fuzzy) { + // Trivial rejection if (src.empty()) { return; } - // Initialize our delimiter string based upon the caller's plus a space - // to allow for more flexibility. + + // 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 === modified file 'util.h' --- util.h 2012-05-01 22:58:28 +0000 +++ util.h 2012-05-02 21:36:04 +0000 @@ -25,25 +25,52 @@ struct Util { /** - * split() - Splits a string into elements separated by a delimiter - * - * @s: the string to split - * @delim: the delimiter to use - * @elems: the string vector to populate - * - * Splits @s into a vector of string elements, delimited by @delim, that - * get returned in @elems. The handling of @delim allows for spaces on - * either side of the delimiter or even multiple consecutive delimiters - * with no elements between. As long as @s is non-empty, there will be - * at least one element in @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); + 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(); @@ -55,6 +82,11 @@ 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) @@ -64,7 +96,11 @@ 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) @@ -73,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);