Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:32

0001 // -*- C++ -*-
0002 //
0003 // EnumIO.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_EnumIO_H
0010 #define ThePEG_EnumIO_H
0011 // This is the declaration of the IEnum and OEnum classes and
0012 // associated templated functions.
0013 
0014 // #include "ThePEG/Config/ThePEG.h"
0015 // #include "EnumIO.fh"
0016 // #include "EnumIO.xh"
0017 
0018 namespace ThePEG {
0019 
0020 template <typename T>
0021 /**
0022  * The <code>OEnum</code> helper class is used to facilitate output of enums
0023  * to persistent streams. An enum can hence be written like this:<BR>
0024  * <code>os >> oenum(x);</code><BR>
0025  *
0026  * @see PersistentOStream
0027  * @see PersistentIStream
0028  * 
0029  */
0030 struct OEnum {
0031 
0032   /** Constructor. */
0033   OEnum(const T & t): theT(t) {}
0034 
0035   /** Copy constructor. */
0036   OEnum(const OEnum & oe): theT(oe.theT) {}
0037 
0038   /** The variable to be written */
0039   const T & theT;
0040 
0041 };
0042 
0043 /**
0044  * The <code>IEnum</code> helper class is used to facilitate input of enums
0045  * from persistent streams. An enum can hence be read like this:<BR>
0046  * <code>is >> ienum(x);</code>
0047  *
0048  * @see PersistentOStream
0049  * @see PersistentIStream
0050  * 
0051  */
0052 template <typename T>
0053 struct IEnum {
0054 
0055   /** Constructor. */
0056   IEnum(T & t): theT(t) {}
0057 
0058   /** Copy constructor. */
0059   IEnum(const IEnum & ie): theT(ie.theT) {}
0060 
0061   /** The variable to be read */
0062   T & theT;
0063 
0064 };
0065 
0066 /** Helper function to create an OEnum object for a given variable. */
0067 template <typename T>
0068 inline OEnum<T> oenum(const T & t) {
0069   return OEnum<T>(t);
0070 }
0071 
0072 /** Helper function to create an IEnum object for a given variable. */
0073 template <typename T>
0074 inline IEnum<T> ienum(T & t) {
0075   return IEnum<T>(t);
0076 }
0077 
0078 /** Overloading of operator<< for OEnum. */
0079 template <typename OStream, typename T>
0080 OStream & operator<<(OStream & os, const OEnum<T> & e) {
0081   os << long(e.theT);
0082   return os;
0083 }
0084 
0085 /** Overloading of operator<< for IEnum. */
0086 template <typename IStream, typename T>
0087 IStream & operator>>(IStream & is, const IEnum<T> & e) {
0088   long l = 0;
0089   is >> l;
0090   e.theT = T(l);
0091   return is;
0092 }
0093 
0094 }
0095 
0096 #endif /* ThePEG_EnumIO_H */