CatapultServer  v0.5.0.1 (Elephant)
NamedObject.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <string>
23 #include <vector>
24 
25 namespace catapult { namespace utils {
26 
29  public:
31  explicit NamedObjectMixin(const std::string& name) : m_name(name)
32  {}
33 
34  public:
36  const std::string& name() const {
37  return m_name;
38  }
39 
40  private:
41  std::string m_name;
42  };
43 
45  template<typename TNamedObjects>
46  std::vector<std::string> ExtractNames(const TNamedObjects& namedObjects) {
47  std::vector<std::string> names;
48  names.reserve(namedObjects.size());
49  for (const auto& pObject : namedObjects)
50  names.push_back(pObject->name());
51 
52  return names;
53  }
54 
56  inline std::string ReduceNames(const std::vector<std::string>& names) {
57  size_t numNames = 0;
58  std::string result = "{";
59  for (const auto& name : names) {
60  if (0 != numNames++)
61  result += ",";
62 
63  result += " ";
64  result += name;
65  }
66 
67  if (0 != numNames)
68  result += " ";
69 
70  result += "}";
71  return result;
72  }
73 }}
catapult::utils::ExtractNames
std::vector< std::string > ExtractNames(const TNamedObjects &namedObjects)
Extracts all names from namedObjects.
Definition: NamedObject.h:46
catapult::utils::NamedObjectMixin::m_name
std::string m_name
Definition: NamedObject.h:41
catapult::utils::NamedObjectMixin::NamedObjectMixin
NamedObjectMixin(const std::string &name)
Creates a mixin with name.
Definition: NamedObject.h:31
catapult::utils::NamedObjectMixin
Mixin to have named objects.
Definition: NamedObject.h:28
catapult::utils::ReduceNames
std::string ReduceNames(const std::vector< std::string > &names)
Reduces names into a single string.
Definition: NamedObject.h:56
catapult::utils::NamedObjectMixin::name
const std::string & name() const
Returns the name.
Definition: NamedObject.h:36
catapult
Definition: AddressExtractionExtension.cpp:28