InputTag_fwd.h
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #pragma once
21 
22 #include <momemta/any.h>
23 
24 #include <memory>
25 #include <stdexcept>
26 #include <string>
27 #include <vector>
28 
37 struct InputTag {
38  public:
44  InputTag(const std::string& module, const std::string& parameter);
51  InputTag(const std::string& module, const std::string& parameter, size_t index);
53  InputTag() = default;
54 
71  static bool isInputTag(const std::string& tag);
72 
81  static InputTag fromString(const std::string& tag);
82 
89  bool operator==(const InputTag& rhs) const;
90 
96  std::string toString() const;
97 
99  bool isIndexed() const;
100 
102  bool empty() const;
103 
105  void update();
106 
107  std::string module;
108  std::string parameter;
109  size_t index;
110 
111  private:
112  class tag_not_resolved_error: public std::runtime_error {
113  using std::runtime_error::runtime_error;
114  };
115 
116  bool indexed = false;
117 
118  std::string string_representation;
119 };
120 
121 namespace std {
123  template<>
124  struct hash<InputTag> {
126  size_t operator()(const InputTag& tag) const {
127  return string_hash(tag.module) + string_hash(tag.parameter);
128  }
129 
130  private:
131  std::hash<std::string> string_hash;
132  };
133 }
bool isIndexed() const
Definition: InputTag.cc:93
void update()
Update the string representation of the InputTag.
Definition: InputTag.cc:101
bool empty() const
Definition: InputTag.cc:97
Definition: optional.h:869
bool operator==(const InputTag &rhs) const
Test equality between two InputTags.
Definition: InputTag.cc:85
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
size_t operator()(const InputTag &tag) const
Compute hash of InputTag.
Definition: InputTag_fwd.h:126
size_t index
The index. Only meaningful if isIndexed() returns true.
Definition: InputTag_fwd.h:109
std::string parameter
The module&#39;s output.
Definition: InputTag_fwd.h:108
std::string toString() const
Convert the InputTag in its string representation.
Definition: InputTag.cc:89
static InputTag fromString(const std::string &tag)
Create a input tag from its string representation.
Definition: InputTag.cc:75
std::string module
The module&#39;s name.
Definition: InputTag_fwd.h:107
InputTag()=default
Construct an empty InputTag.
static bool isInputTag(const std::string &tag)
Check if a given string represent an InputTag.
Definition: InputTag.cc:54