SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
basetag.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Written (W) 2016 Sergey Lisitsyn
32  * Written (W) 2016 Sanuj Sharma
33  */
34 
35 #ifndef _BASETAG_H_
36 #define _BASETAG_H_
37 
38 #include <string>
39 
40 namespace shogun
41 {
48  class BaseTag
49  {
50  public:
51 
55  explicit BaseTag(const std::string& _name) :
56  m_name(_name), m_hash(std::hash<std::string>()(_name))
57  {
58  }
59 
63  BaseTag(const BaseTag& other) :
64  m_name(other.m_name), m_hash(other.m_hash)
65  {
66  }
67 
71  BaseTag& operator=(const BaseTag& other)
72  {
73  m_name = other.m_name;
74  m_hash = other.m_hash;
75  return *this;
76  }
77 
79  inline std::string name() const
80  {
81  return m_name;
82  }
83 
85  inline std::size_t hash() const
86  {
87  return m_hash;
88  }
89 
94  friend inline bool operator==(const BaseTag& first, const BaseTag& second);
95 
100  friend inline bool operator!=(const BaseTag& first, const BaseTag& second);
101 
106  friend inline bool operator<(const BaseTag& first, const BaseTag& second);
107 
108  private:
110  std::string m_name;
112  size_t m_hash;
113  };
114 
115  inline bool operator==(const BaseTag& first, const BaseTag& second)
116  {
117  return first.m_hash == second.m_hash ? first.m_name == second.m_name : false;
118  }
119 
120  inline bool operator!=(const BaseTag& first, const BaseTag& second)
121  {
122  return !(first == second);
123  }
124 
125  inline bool operator<(const BaseTag& first, const BaseTag& second)
126  {
127  return first.m_name < second.m_name;
128  }
129 
130 }
131 
132 namespace std
133 {
135  template <>
136  struct hash<shogun::BaseTag>
137  {
138  std::size_t operator()(const shogun::BaseTag& basetag) const
139  {
140  return basetag.hash();
141  }
142  };
143 
144 }
145 
146 #endif // _BASETAG_H_
std::size_t hash() const
Definition: basetag.h:85
BaseTag & operator=(const BaseTag &other)
Definition: basetag.h:71
bool operator<(const BaseTag &first, const BaseTag &second)
Definition: basetag.h:125
bool operator==(const Any &lhs, const Any &rhs)
Definition: any.h:264
Base class for all tags. This class stores name and not the type information for a shogun object...
Definition: basetag.h:48
Definition: basetag.h:132
BaseTag(const std::string &_name)
Definition: basetag.h:55
std::string name() const
Definition: basetag.h:79
friend bool operator!=(const BaseTag &first, const BaseTag &second)
Definition: basetag.h:120
bool operator!=(const Any &lhs, const Any &rhs)
Definition: any.h:272
friend bool operator<(const BaseTag &first, const BaseTag &second)
Definition: basetag.h:125
friend bool operator==(const BaseTag &first, const BaseTag &second)
Definition: basetag.h:115
std::size_t operator()(const shogun::BaseTag &basetag) const
Definition: basetag.h:138
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
BaseTag(const BaseTag &other)
Definition: basetag.h:63

SHOGUN Machine Learning Toolbox - Documentation