| Line | % of fetches | Source |
|---|---|---|
| 1 | // Copyright (c) 2014 University of Oregon | |
| 2 | // | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 5 | ||
| 6 | #pragma once | |
| 7 | ||
| 8 | #include "apex_types.h" | |
| 9 | #include "utils.hpp" | |
| 10 | #include <functional> | |
| 11 | #include <string> | |
| 12 | ||
| 13 | namespace apex { | |
| 14 | ||
| 15 | class task_identifier { | |
| 16 | public: | |
| 17 | apex_function_address address; | |
| 18 | std::string name; | |
| 19 | std::string _resolved_name; | |
| 20 | bool has_name; | |
| 21 | task_identifier(void) : | |
| 22 | address(0L), name(""), _resolved_name(""), has_name(false) {}; | |
| 23 | task_identifier(apex_function_address a) : | |
| 24 | address(a), name(""), _resolved_name(""), has_name(false) {}; | |
| 25 | task_identifier(std::string n) : | |
| 26 | address(0L), name(demangle(n)), _resolved_name(""), has_name(true) {}; | |
| 27 | /* | |
| 28 | task_identifier(profiler * p) : | |
| 29 | address(0L), name(""), _resolved_name("") { | |
| 30 | if (p->have_name) { | |
| 31 | name = *p->timer_name; | |
| 32 | has_name = true; | |
| 33 | } else { | |
| 34 | address = p->action_address; | |
| 35 | has_name = false; | |
| 36 | } | |
| 37 | } | |
| 38 | */ | |
| 39 | std::string get_name(); | |
| 40 | ~task_identifier() { } | |
| 41 | // requried for using this class as a key in an unordered map. | |
| 42 | // the hash function is defined below. | |
| 43 | bool operator==(const task_identifier &other) const { | |
| 44 | return (address == other.address && name.compare(other.name) == 0); | |
| 45 | } | |
| 46 | // required for using this class as a key in a set | |
| 47 | bool operator< (const task_identifier &right) const { | |
| 48 | if (!has_name) { | |
| 49 | if (!right.has_name) { | |
| 50 | // if both have an address, return the lower address | |
| 51 | return (address < right.address); | |
| 52 | } else { | |
| 53 | // if left has an address and right doesn't, return true | |
| 54 | return true; | |
| 55 | } | |
| 56 | } else { | |
| 57 | if (right.has_name) { | |
| 58 | // if both have a name, return the lower name | |
| 59 | return (name < right.name); | |
| 60 | } | |
| 61 | } | |
| 62 | // if right has an address and left doesn't, return false | |
| 63 | // (also the default) | |
| 64 | return false; | |
| 65 | } | |
| 66 | }; | |
| 67 | ||
| 68 | } | |
| 69 | ||
| 70 | /* This is the hash function for the task_identifier class */ | |
| 71 | namespace std { | |
| 72 | ||
| 73 | template <> | |
| 74 | struct hash<apex::task_identifier> | |
| 75 | { | |
| 76 | std::size_t operator()(const apex::task_identifier& k) const | |
| 77 | { | |
| 78 | std::size_t h1 = std::hash<std::size_t>()(k.address); | |
| 79 | std::size_t h2 = std::hash<std::string>()(k.name); | |
| 80 | return h1 ^ (h2 << 1);; // instead of boost::hash_combine | |
| 81 | } | |
| 82 | }; | |
| 83 | ||
| 84 | } | |
| 85 | ||
| 86 | ||
| 87 |
Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.