CDF II
CDF KITS
source navigation ]
diff markup ]
identifier search ]
freetext search ]
file search ]
 
Architecture: i386 ]
Version: 4.10.4 ] [ 4.10.5 ] [ 4.8.4 ] [ 4.8.4l3s ] [ 4.8.5 ] [ 4.9.0 ] [ 4.9.1 ] [ 4.9.1.hpt3 ] [ 4.9.1hpt3 ] [ 4.9.1top1 ] [ 5.0.0 ] [ 5.1.0 ] [ 5.1.0beamonly ] [ 5.1.1 ] [ 5.2.0 ] [ 5.3.0 ] [ 5.3.1 ] [ 5.3.1dsp ] [ 5.3.3 ] [ 5.3.3_nt ] [ 5.3.4 ] [ 6.1.1 ] [ 6.1.1b ] [ 6.1.2 ] [ 6.1.3 ] [ 6.1.4 ] [ 6.1.4int3 ] [ 6.1.4mc ] [ 6.1.4mc_a ] [ 6.1.6 ] [ development ]

001 #ifndef _GRAYCODE_HH_
002 #define _GRAYCODE_HH_
003 
004 // Remove this for speed (at the expense of safety)
005 #define GRAYCODE_RANGECHECK
006 
007 #include <iosfwd>
008 #include <string>
009 
010 class GrayCode {
011 
012 public:
013 
014   GrayCode(); 
015   // Default constructor
016 
017   GrayCode(int grayCode);
018   // Constructor with arguments
019 
020   GrayCode(const GrayCode& right);
021   // Copy constructor
022 
023   ~GrayCode();
024   // Destructor
025 
026   static GrayCode decToGray(int decNum);
027   // Initialize a GrayCode from a decimal number. This is a static
028   // method, so you can use it as a simple converter if you
029   // wish. Suggested usage:
030   //
031   //     GrayCode gc = GrayCode::decToGray(decNum);
032   //
033   // Note simply doing:
034   //
035   //     GrayCode gc(num) will initialize the object using num as a
036   //     GrayCode (ie no conversion takes place)
037   //
038   // See SvxDaqUtils/test/testGrayCode.cc for more usage examples.
039 
040   static void initLUTs();
041   // Initialize look-up tables. This is a static, public method to allow
042   // users (should they wish) to bypass the first-event overhead that
043   // would otherwise result.
044 
045   std::string asBitStream() const ;
046   // Return the GrayCode as a string of 0s and 1s
047   
048   inline int grayCode() const;
049   // Return the GrayCode unconverted
050   
051   inline operator int() const;
052   // Returns the GrayCode converted back to a `normal' number.
053   // 
054   // WARNING -- this is an implicit cast ie it will occur whenever you're
055   // using a GrayCode where an int is expected. If you're actually trying
056   // to do operations on GrayCodes as GrayCodes you'd better make sure the
057   // methods you're using actually exist!
058   
059   inline GrayCode& operator= (const int gc);
060   inline GrayCode& operator= (const GrayCode& gc);
061   inline GrayCode& operator+=(const int gc);
062   inline GrayCode& operator+=(const GrayCode& gc);
063   inline GrayCode& operator-=(const int gc);
064   inline GrayCode& operator-=(const GrayCode& gc);
065   inline GrayCode& operator*=(const int gc);
066   inline GrayCode& operator*=(const GrayCode& gc);
067   inline GrayCode& operator/=(const int gc);
068   inline GrayCode& operator/=(const GrayCode& gc);
069   // Arithmetic assignment operators 
070   //
071   // Note all these operators (as a matter of policy) operate with
072   // GrayCodes. If you want to operate on the converted numbers, use the
073   // explicit int() cast
074   
075   inline GrayCode& operator++();
076   inline GrayCode  operator++(int);
077   inline GrayCode& operator--();
078   inline GrayCode  operator--(int);
079   // Increments and decrements
080 
081   inline bool operator==(const GrayCode& gc) const;
082   inline bool operator!=(const GrayCode& gc) const;
083   inline bool operator>=(const GrayCode& gc) const;
084   inline bool operator<=(const GrayCode& gc) const;
085   inline bool operator> (const GrayCode& gc) const;
086   inline bool operator< (const GrayCode& gc) const;
087   // Relational operators
088 
089   inline GrayCode& operator|= (const GrayCode& gc);
090   inline GrayCode& operator&= (const GrayCode& gc);
091   inline GrayCode& operator^= (const GrayCode& gc);
092   inline GrayCode& operator<<=(size_t n);
093   inline GrayCode& operator>>=(size_t n);
094   // Bitwise assignment operators
095 
096   inline GrayCode operator<<(size_t n) const;
097   inline GrayCode operator>>(size_t n) const;
098   inline GrayCode operator~() const;
099   inline friend GrayCode operator&(const GrayCode& gc1, const GrayCode& gc2);
100   inline friend GrayCode operator|(const GrayCode& gc1, const GrayCode& gc2);
101   inline friend GrayCode operator^(const GrayCode& gc1, const GrayCode& gc2);
102   inline friend GrayCode operator&(int gc1, const GrayCode& gc2);
103   inline friend GrayCode operator|(int gc1, const GrayCode& gc2);
104   inline friend GrayCode operator^(int gc1, const GrayCode& gc2);
105   inline friend GrayCode operator&(const GrayCode& gc1, int gc2);
106   inline friend GrayCode operator|(const GrayCode& gc1, int gc2);
107   inline friend GrayCode operator^(const GrayCode& gc1, int gc2);
108   // Logical operators
109 
110   inline friend GrayCode operator+(const GrayCode& gc1, const GrayCode& gc2);
111   inline friend GrayCode operator-(const GrayCode& gc1, const GrayCode& gc2);
112   inline friend GrayCode operator*(const GrayCode& gc1, const GrayCode& gc2);
113   inline friend GrayCode operator/(const GrayCode& gc1, const GrayCode& gc2);
114   inline friend GrayCode operator+(int gc1, const GrayCode& gc2);
115   inline friend GrayCode operator-(int gc1, const GrayCode& gc2);
116   inline friend GrayCode operator*(int gc1, const GrayCode& gc2);
117   inline friend GrayCode operator/(int gc1, const GrayCode& gc2);
118   inline friend GrayCode operator+(const GrayCode& gc1, int gc2);
119   inline friend GrayCode operator-(const GrayCode& gc1, int gc2);
120   inline friend GrayCode operator*(const GrayCode& gc1, int gc2);
121   inline friend GrayCode operator/(const GrayCode& gc1, int gc2);
122   // Arithmetic operations 
123   
124   friend std::ostream& operator<< (std::ostream& s, const GrayCode& grayCode);
125   // Operator<< for easy output on streams. To output the GrayCode
126   // converted back to a normal number do:
127   //
128   //     stream << int(gc) << std::endl; // or whatever
129 
130 private:
131 
132   static int const MAX_GRAYCODE = 256;
133 
134   static int _gray[MAX_GRAYCODE];
135   static int _dec[MAX_GRAYCODE];
136 
137   static bool _isInitialized;
138 
139   int _grayCode;
140 
141 };
142 
143 #include "TrackingObjects/SiData/GrayCode.icc"
144 
145 #endif

source navigation ] diff markup ] identifier search ] freetext search ] file search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!

Send problems or questions to cdfcode@fnal.gov