Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
fhicl::ParameterSetID Class Reference

#include <ParameterSetID.h>

Public Member Functions

 ParameterSetID () noexcept
 
 ParameterSetID (ParameterSet const &)
 
 ParameterSetID (std::string const &id)
 
bool is_valid () const noexcept
 
std::string to_string () const
 
void invalidate () noexcept
 
void reset (ParameterSet const &)
 
void swap (ParameterSetID &)
 
bool operator== (ParameterSetID const &) const noexcept
 
bool operator!= (ParameterSetID const &) const noexcept
 
bool operator< (ParameterSetID const &) const noexcept
 
bool operator> (ParameterSetID const &) const noexcept
 
bool operator<= (ParameterSetID const &) const noexcept
 
bool operator>= (ParameterSetID const &) const noexcept
 

Static Public Member Functions

static constexpr std::size_t max_str_size () noexcept
 

Private Attributes

bool valid_
 
cet::sha1::digest_t id_
 

Detailed Description

Definition at line 23 of file ParameterSetID.h.

Constructor & Destructor Documentation

ParameterSetID::ParameterSetID ( )
noexcept

Definition at line 23 of file ParameterSetID.cc.

23 : valid_{false}, id_{invalid_id} {}
cet::sha1::digest_t id_
constexpr sha1::digest_t invalid_id
ParameterSetID::ParameterSetID ( ParameterSet const &  ps)
explicit

Definition at line 25 of file ParameterSetID.cc.

25  : valid_{false}, id_{}
26 {
27  reset(ps);
28 }
cet::sha1::digest_t id_
static constexpr double ps
Definition: Units.h:99
void reset(ParameterSet const &)
ParameterSetID::ParameterSetID ( std::string const &  id)
explicit

Definition at line 30 of file ParameterSetID.cc.

31  : valid_{id.size() == max_str_size()}, id_{}
32 {
33  if (valid_) {
34  for (size_t i = 0, e = id_.size(); i != e; ++i) {
35  id_[i] = std::stoi(id.substr(i * 2, 2), nullptr, 16);
36  }
37  if (id != to_string()) {
39  << "ParameterSetID construction failure: " << id
40  << " != " << to_string() << ".\n";
41  }
42  } else if (id.empty()) {
43  id_ = invalid_id;
44  } else {
46  << "Attempt to construct ParameterSetID from inappropriate input: " << id
47  << ".\n";
48  }
49 }
std::string to_string() const
cet::sha1::digest_t id_
const double e
static constexpr std::size_t max_str_size() noexcept
constexpr sha1::digest_t invalid_id
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97

Member Function Documentation

void ParameterSetID::invalidate ( )
noexcept

Definition at line 75 of file ParameterSetID.cc.

76 {
77  valid_ = false;
78  id_ = invalid_id;
79 }
cet::sha1::digest_t id_
constexpr sha1::digest_t invalid_id
bool ParameterSetID::is_valid ( ) const
noexcept

Definition at line 54 of file ParameterSetID.cc.

55 {
56  return valid_;
57 }
constexpr std::size_t fhicl::ParameterSetID::max_str_size ( )
inlinestaticnoexcept

Definition at line 55 of file ParameterSetID.h.

56 {
57  // Two hex digits per byte.
58  return 2 * cet::sha1::digest_sz;
59 }
static std::size_t constexpr digest_sz
Definition: sha1.h:28
bool ParameterSetID::operator!= ( ParameterSetID const &  other) const
noexcept

Definition at line 107 of file ParameterSetID.cc.

108 {
109  return id_ != other.id_;
110 }
cet::sha1::digest_t id_
bool ParameterSetID::operator< ( ParameterSetID const &  other) const
noexcept

Definition at line 113 of file ParameterSetID.cc.

114 {
115  return id_ < other.id_;
116 }
cet::sha1::digest_t id_
bool ParameterSetID::operator<= ( ParameterSetID const &  other) const
noexcept

Definition at line 125 of file ParameterSetID.cc.

126 {
127  return id_ <= other.id_;
128 }
cet::sha1::digest_t id_
bool ParameterSetID::operator== ( ParameterSetID const &  other) const
noexcept

Definition at line 101 of file ParameterSetID.cc.

102 {
103  return id_ == other.id_;
104 }
cet::sha1::digest_t id_
bool ParameterSetID::operator> ( ParameterSetID const &  other) const
noexcept

Definition at line 119 of file ParameterSetID.cc.

120 {
121  return id_ > other.id_;
122 }
cet::sha1::digest_t id_
bool ParameterSetID::operator>= ( ParameterSetID const &  other) const
noexcept

Definition at line 131 of file ParameterSetID.cc.

132 {
133  return id_ >= other.id_;
134 }
cet::sha1::digest_t id_
void ParameterSetID::reset ( ParameterSet const &  ps)

Definition at line 82 of file ParameterSetID.cc.

83 {
84  auto const& hash = ps.to_string();
85  sha1 sha{hash.c_str()};
86 
87  id_ = sha.digest();
88  valid_ = true;
89 }
Definition: sha1.h:26
cet::sha1::digest_t id_
static constexpr double ps
Definition: Units.h:99
void ParameterSetID::swap ( ParameterSetID other)

Definition at line 92 of file ParameterSetID.cc.

93 {
94  id_.swap(other.id_);
95  std::swap(valid_, other.valid_);
96 }
cet::sha1::digest_t id_
void swap(Handle< T > &a, Handle< T > &b)
string ParameterSetID::to_string ( ) const

Definition at line 60 of file ParameterSetID.cc.

61 {
62  std::ostringstream oss;
63  oss << std::hex << std::setfill('0');
64  // The range-for loop performs an implicit cast from 'unsigned char'
65  // to 'unsigned int'.
66  for (unsigned int const num : id_) {
67  oss << std::setw(2) << num;
68  }
69  return oss.str();
70 }
QTextStream & hex(QTextStream &s)
cet::sha1::digest_t id_
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337

Member Data Documentation

cet::sha1::digest_t fhicl::ParameterSetID::id_
private

Definition at line 50 of file ParameterSetID.h.

bool fhicl::ParameterSetID::valid_
private

Definition at line 49 of file ParameterSetID.h.


The documentation for this class was generated from the following files: