thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
EnumIO.h
1// -*- C++ -*-
2//
3// EnumIO.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_EnumIO_H
10#define ThePEG_EnumIO_H
11// This is the declaration of the IEnum and OEnum classes and
12// associated templated functions.
13
14// #include "ThePEG/Config/ThePEG.h"
15// #include "EnumIO.fh"
16// #include "EnumIO.xh"
17
18namespace ThePEG {
19
20template <typename T>
30struct OEnum {
31
33 OEnum(const T & t): theT(t) {}
34
36 OEnum(const OEnum & oe): theT(oe.theT) {}
37
39 const T & theT;
40
41};
42
52template <typename T>
53struct IEnum {
54
56 IEnum(T & t): theT(t) {}
57
59 IEnum(const IEnum & ie): theT(ie.theT) {}
60
62 T & theT;
63
64};
65
67template <typename T>
68inline OEnum<T> oenum(const T & t) {
69 return OEnum<T>(t);
70}
71
73template <typename T>
74inline IEnum<T> ienum(T & t) {
75 return IEnum<T>(t);
76}
77
79template <typename OStream, typename T>
80OStream & operator<<(OStream & os, const OEnum<T> & e) {
81 os << long(e.theT);
82 return os;
83}
84
86template <typename IStream, typename T>
87IStream & operator>>(IStream & is, const IEnum<T> & e) {
88 long l = 0;
89 is >> l;
90 e.theT = T(l);
91 return is;
92}
93
94}
95
96#endif /* ThePEG_EnumIO_H */
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
vector< T > & operator>>(vector< T > &tv, U &u)
Overload the right shift operator for vector to pop objects from a vector.
Definition: Containers.h:192
IEnum< T > ienum(T &t)
Helper function to create an IEnum object for a given variable.
Definition: EnumIO.h:74
vector< T > & operator<<(vector< T > &tv, const U &u)
Overload the left shift operator for vector to push_back objects to a vector.
Definition: Containers.h:179
OEnum< T > oenum(const T &t)
Helper function to create an OEnum object for a given variable.
Definition: EnumIO.h:68
The IEnum helper class is used to facilitate input of enums from persistent streams.
Definition: EnumIO.h:53
IEnum(T &t)
Constructor.
Definition: EnumIO.h:56
T & theT
The variable to be read.
Definition: EnumIO.h:62
IEnum(const IEnum &ie)
Copy constructor.
Definition: EnumIO.h:59
The OEnum helper class is used to facilitate output of enums to persistent streams.
Definition: EnumIO.h:30
OEnum(const OEnum &oe)
Copy constructor.
Definition: EnumIO.h:36
const T & theT
The variable to be written.
Definition: EnumIO.h:39
OEnum(const T &t)
Constructor.
Definition: EnumIO.h:33