~glcompbench-dev/glcompbench/blur-update

« back to all changes in this revision

Viewing changes to src/libmatrix/util.h

  • Committer: Jesse Barker
  • Date: 2012-01-27 22:26:02 UTC
  • mfrom: (74.1.5 libmatrix-util)
  • Revision ID: jesse.barker@linaro.org-20120127222602-osainr4na7opoiij
Merge of lp:~glcompbench-dev/glcompbench/libmatrix-util.

Updates glcompbench to reflect the latest lp:libmatrix, which, in and of itself,
conslidates code previously duplicated between glcompbench and glmark2 into
libmatrix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2010-2011 Linaro Limited
 
3
//
 
4
// All rights reserved. This program and the accompanying materials
 
5
// are made available under the terms of the MIT License which accompanies
 
6
// this distribution, and is available at
 
7
// http://www.opensource.org/licenses/mit-license.php
 
8
//
 
9
// Contributors:
 
10
//     Alexandros Frantzis <alexandros.frantzis@linaro.org>
 
11
//     Jesse Barker <jesse.barker@linaro.org>
 
12
//
 
13
#ifndef UTIL_H_
 
14
#define UTIL_H_
 
15
 
 
16
#include <string>
 
17
#include <vector>
 
18
#include <istream>
 
19
#include <sstream>
 
20
#include <stdint.h>
 
21
 
 
22
#ifdef ANDROID
 
23
#include <android/asset_manager_jni.h>
 
24
#endif
 
25
 
 
26
struct Util {
 
27
    static void split(const std::string &s, char delim, std::vector<std::string> &elems);
 
28
    static uint64_t get_timestamp_us();
 
29
    static std::istream *get_resource(const std::string &path);
 
30
    static void list_files(const std::string& dirName, std::vector<std::string>& fileVec);
 
31
    template <class T> static void dispose_pointer_vector(std::vector<T*> &vec)
 
32
    {
 
33
        for (typename std::vector<T*>::const_iterator iter = vec.begin();
 
34
             iter != vec.end();
 
35
             iter++)
 
36
        {
 
37
            delete *iter;
 
38
        }
 
39
 
 
40
        vec.clear();
 
41
    }
 
42
    template<typename T>
 
43
    static T
 
44
    fromString(const std::string& asString)
 
45
    {
 
46
        std::stringstream ss(asString);
 
47
        T retVal;
 
48
        ss >> retVal;
 
49
        return retVal;
 
50
    }
 
51
 
 
52
    template<typename T>
 
53
    static std::string
 
54
    toString(const T t)
 
55
    {
 
56
        std::stringstream ss;
 
57
        ss << t;
 
58
        return ss.str();
 
59
    }
 
60
    static std::string
 
61
    appname_from_path(const std::string& path);
 
62
 
 
63
#ifdef ANDROID
 
64
    static void android_set_asset_manager(AAssetManager *asset_manager);
 
65
    static AAssetManager *android_get_asset_manager(void);
 
66
private:
 
67
    static AAssetManager *android_asset_manager;
 
68
#endif
 
69
};
 
70
 
 
71
#endif /* UTIL_H */