thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 
18 namespace ThePEG {
19 
20 template <typename T>
30 struct 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 
52 template <typename T>
53 struct IEnum {
54 
56  IEnum(T & t): theT(t) {}
57 
59  IEnum(const IEnum & ie): theT(ie.theT) {}
60 
62  T & theT;
63 
64 };
65 
67 template <typename T>
68 inline OEnum<T> oenum(const T & t) {
69  return OEnum<T>(t);
70 }
71 
73 template <typename T>
74 inline IEnum<T> ienum(T & t) {
75  return IEnum<T>(t);
76 }
77 
79 template <typename OStream, typename T>
80 OStream & operator<<(OStream & os, const OEnum<T> & e) {
81  os << long(e.theT);
82  return os;
83 }
84 
86 template <typename IStream, typename T>
87 IStream & 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 */
The OEnum helper class is used to facilitate output of enums to persistent streams.
Definition: EnumIO.h:30
IEnum< T > ienum(T &t)
Helper function to create an IEnum object for a given variable.
Definition: EnumIO.h:74
IEnum(T &t)
Constructor.
Definition: EnumIO.h:56
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
OEnum< T > oenum(const T &t)
Helper function to create an OEnum object for a given variable.
Definition: EnumIO.h:68
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
T & theT
The variable to be read.
Definition: EnumIO.h:62
OEnum(const OEnum &oe)
Copy constructor.
Definition: EnumIO.h:36
IEnum(const IEnum &ie)
Copy constructor.
Definition: EnumIO.h:59
OEnum(const T &t)
Constructor.
Definition: EnumIO.h:33
const T & theT
The variable to be written.
Definition: EnumIO.h:39
The IEnum helper class is used to facilitate input of enums from persistent streams.
Definition: EnumIO.h:53