timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
python_class_name.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25#pragma once
26
27#include <cctype>
28#include <cstddef>
29#include <string>
30
31namespace tim
32{
33//
34namespace component
35{
36template <typename Tp>
37struct properties;
38}
39//
40namespace operation
41{
42//
43template <typename Tp>
44struct python_class_name;
45//
46//--------------------------------------------------------------------------------------//
47//
48///
49/// \struct tim::operation::python_class_name
50/// \brief This class generates the class name for a component according to the standard
51/// Python naming convention
52///
53//
54//--------------------------------------------------------------------------------------//
55//
56template <>
58{
60};
61//
62template <typename Tp>
64{
65 using type = Tp;
67
68 using base_type::operator();
70 {
72 static_assert(properties_t::specialized(),
73 "Error! Cannot get python class name if the component properties "
74 "have not been specialized");
75 return this->base_type::operator()(properties_t::enum_string());
76 }
77};
78//
79//--------------------------------------------------------------------------------------//
80//
81inline std::string
83{
84 if(id.empty())
85 return std::string{};
86
87 for(auto& itr : id)
88 itr = ::tolower(itr);
89
90 // capitalize after every delimiter
91 for(size_t i = 0; i < id.size(); ++i)
92 {
93 if(i == 0)
94 id.at(i) = ::toupper(id.at(i));
95 else
96 {
97 if((id.at(i) == '_' || id.at(i) == '-') && i + 1 < id.length())
98 {
99 id.at(i + 1) = ::toupper(id.at(i + 1));
100 ++i;
101 }
102 }
103 }
104 // remove all delimiters
105 for(auto ditr : { '_', '-' })
106 {
107 size_t _pos = 0;
108 while((_pos = id.find(ditr)) != std::string::npos)
109 id = id.erase(_pos, 1);
110 }
111
112 return id;
113}
114//
115//--------------------------------------------------------------------------------------//
116//
117} // namespace operation
118} // namespace tim
typename enumerator< Idx >::type properties_t
Definition: properties.hpp:276
Definition: kokkosp.cpp:39
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
_args at(0)
This is a critical specialization for mapping string and integers to component types at runtime....
Definition: properties.hpp:214
std::string operator()(std::string id) const
This class generates the class name for a component according to the standard Python naming conventio...