Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

Addressing.h

00001 
00002 #ifndef SCT_ADDRESSING_H
00003 #define SCT_ADDRESSING_H
00004 
00005 #include <iostream>
00006 #include <string>
00007 
00008 namespace Sct {
00009   
00011   typedef unsigned int       PartitionIdentifier;
00012 
00014   typedef unsigned int           CrateIdentifier;
00015 
00017   typedef unsigned int             RodIdentifier;
00018 
00019   // forward declarations
00020   class UniquePartitionIdentifier;
00021   class UniqueCrateIdentifier;
00022   class UniqueRodIdentifier;
00023   class UniqueTimIdentifier;
00024 
00025   // shorter forms:
00026   typedef UniquePartitionIdentifier UPID;
00027   typedef UniqueCrateIdentifier     UCID;
00028   typedef UniqueRodIdentifier       URID;
00029   typedef UniqueTimIdentifier       UTID;
00030 
00031   // defns:
00032 
00034   class UniquePartitionIdentifier {
00035     PartitionIdentifier m_partition;
00036   public:
00037     UniquePartitionIdentifier(const UniquePartitionIdentifier & other) :
00038       m_partition(other.m_partition) {
00039     };
00040     explicit UniquePartitionIdentifier(const PartitionIdentifier p) :
00041       m_partition(p) {
00042     };
00047     explicit UniquePartitionIdentifier(const std::string & s);
00048     UniquePartitionIdentifier() {};
00049     UniquePartitionIdentifier & operator=(const UniquePartitionIdentifier & other) {
00050       m_partition = other.m_partition;
00051       return *this;
00052     };
00053     bool operator==(const UniquePartitionIdentifier & other) const {
00054       return m_partition == other.m_partition;
00055     };
00056     bool operator!=(const UniquePartitionIdentifier & other) const {
00057       return m_partition != other.m_partition;
00058     };
00059     PartitionIdentifier partition() const {
00060       return m_partition;
00061     };
00062     operator std::string () const;
00063     bool operator<(const UniquePartitionIdentifier & other) const {
00064       return this->m_partition < other.m_partition;
00065     };
00066   private:
00067     std::string tag() const { return "UPID"; };
00068   };
00069   
00072   class UniqueCrateLevelIdentifierBase {
00073     UniquePartitionIdentifier m_partition;
00074     CrateIdentifier           m_crate;
00075   public:
00076     UniqueCrateLevelIdentifierBase(const UniquePartitionIdentifier p,
00077                    const CrateIdentifier c) : 
00078       m_partition(p),
00079       m_crate(c) {
00080     };
00081     UniqueCrateLevelIdentifierBase(const PartitionIdentifier p,
00082                    const CrateIdentifier c) : 
00083       m_partition(p),
00084       m_crate(c) {
00085     };
00086     UniqueCrateLevelIdentifierBase() {};
00087     
00088   public:
00090     UniquePartitionIdentifier upid() const { return m_partition; };
00091 
00092   public:
00094     PartitionIdentifier partition() const { return m_partition.partition(); };
00095 
00097     CrateIdentifier crate() const { return m_crate; };
00098 
00099   protected: // Protected because we don't want people to be able to compare different specialisations with each other,or work with the bases themselves.
00100     UniqueCrateLevelIdentifierBase & operator=(const UniqueCrateLevelIdentifierBase & other) {
00101       m_partition = other.m_partition;
00102       m_crate = other.m_crate;
00103       return *this;
00104     };
00105     bool operator==(const UniqueCrateLevelIdentifierBase & other) const {
00106       return 
00107     m_crate     == other.m_crate &&
00108     m_partition == other.m_partition;
00109     };
00110     bool operator!=(const UniqueCrateLevelIdentifierBase & other) const {
00111       return 
00112     m_crate     != other.m_crate ||
00113     m_partition != other.m_partition;
00114     };
00115     bool operator<(const UniqueCrateLevelIdentifierBase & other) const {
00116       return 
00117     m_partition < other.m_partition ||
00118     m_partition == other.m_partition && m_crate < other.m_crate;
00119     };
00120     const UniqueCrateLevelIdentifierBase & base() const {
00121       return *this;
00122     };
00123     UniqueCrateLevelIdentifierBase & base() {
00124       return *this;
00125     };
00126   };
00127 
00129   class UniqueCrateIdentifier : 
00130     public UniqueCrateLevelIdentifierBase {
00131   public:
00132     UniqueCrateIdentifier(const UniquePartitionIdentifier p,
00133               const CrateIdentifier c) : 
00134       UniqueCrateLevelIdentifierBase(p,c) {
00135     };
00136     UniqueCrateIdentifier(const PartitionIdentifier p,
00137               const CrateIdentifier c) : 
00138       UniqueCrateLevelIdentifierBase(p,c) {
00139     };
00144     explicit UniqueCrateIdentifier(const std::string & s);
00145     UniqueCrateIdentifier() {};
00146     // Not necessary: default will do!
00147     /*
00148       UniqueCrateIdentifier & operator=(const UniqueCrateIdentifier & other) {
00149       this->UniqueCrateLevelIdentifierBase::operator=(other);
00150       return *this;
00151       };
00152     */
00153     bool operator==(const UniqueCrateIdentifier & other) const {
00154       return this->UniqueCrateLevelIdentifierBase::operator==(other);
00155     };
00156     bool operator!=(const UniqueCrateIdentifier & other) const {
00157       return this->UniqueCrateLevelIdentifierBase::operator!=(other);
00158     };
00159     bool operator<(const UniqueCrateIdentifier & other) const {
00160       return this->UniqueCrateLevelIdentifierBase::operator<(other);
00161     };
00162     operator std::string () const;
00163   private:
00164     std::string tag() const { return "UCID"; };
00165   };
00166   
00169   class UniqueTimIdentifier :
00170     public UniqueCrateLevelIdentifierBase {
00171   public:
00172     UniqueTimIdentifier(const UniquePartitionIdentifier p,
00173             const CrateIdentifier c) : 
00174       UniqueCrateLevelIdentifierBase(p,c) {
00175     };
00176     UniqueTimIdentifier(const PartitionIdentifier p,
00177             const CrateIdentifier c) : 
00178       UniqueCrateLevelIdentifierBase(p,c) {
00179     };
00180     UniqueTimIdentifier(const std::string & s);
00181     UniqueTimIdentifier() {};
00182     // Not necessary: default will do!
00183     /*
00184       UniqueTimIdentifier & operator=(const UniqueTimIdentifier & other) {
00185       this->UniqueCrateLevelIdentifierBase::operator=(other);
00186       return *this;
00187       };
00188     */
00189     bool operator==(const UniqueTimIdentifier & other) const {
00190       return this->UniqueCrateLevelIdentifierBase::operator==(other);
00191     };
00192     bool operator!=(const UniqueTimIdentifier & other) const {
00193       return this->UniqueCrateLevelIdentifierBase::operator!=(other);
00194     };
00195     bool operator<(const UniqueTimIdentifier & other) const {
00196       return this->UniqueCrateLevelIdentifierBase::operator<(other);
00197     };
00198     operator std::string () const;
00199   private:
00200     std::string tag() const { return "UTID"; };
00201   };
00202 
00204   class UniqueRodIdentifier {
00205     UniqueCrateIdentifier m_ucid;
00206     RodIdentifier         m_rid;
00207   public:
00208     UniqueRodIdentifier(const UniqueCrateIdentifier c,
00209             const RodIdentifier r) : 
00210       m_ucid(c),
00211       m_rid(r) {
00212     };
00213     UniqueRodIdentifier(const PartitionIdentifier p,
00214             const CrateIdentifier c,
00215             const RodIdentifier r) : 
00216       m_ucid(UniqueCrateIdentifier(p,c)),
00217       m_rid(r) {
00218     };
00223     explicit UniqueRodIdentifier(const std::string & s);
00224     UniqueRodIdentifier() {};
00225       
00226   public:
00228     UniquePartitionIdentifier upid() const { return m_ucid.upid(); };
00229 
00231     UniqueCrateIdentifier ucid() const { return m_ucid; };
00232 
00233   public:
00235     PartitionIdentifier partition() const { return m_ucid.partition(); };
00236 
00238     RodIdentifier crate() const { return m_ucid.crate(); };
00239 
00241     RodIdentifier rod() const { return m_rid; };
00242 
00244 
00245     bool operator==(const UniqueRodIdentifier & other) const {
00246       return
00247     m_rid  == other.m_rid &&
00248     m_ucid == other.m_ucid;
00249     };
00250     bool operator!=(const UniqueRodIdentifier & other) const {
00251       return
00252     m_rid  != other.m_rid ||
00253     m_ucid != other.m_ucid;
00254     };
00255     bool operator<(const UniqueRodIdentifier & other) const {
00256       return 
00257     m_ucid < other.m_ucid ||
00258     m_ucid == other.m_ucid && m_rid < other.m_rid;
00259     };
00260     operator std::string () const;
00261   private:
00262     std::string tag() const { return "URID"; };
00263   };
00264 
00265 }
00266  
00267 inline std::ostream & operator<<(std::ostream & os, const Sct::UniquePartitionIdentifier & upid) {
00268   return os << std::string(upid);
00269 };
00270 
00271 inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueCrateIdentifier & ucid) {
00272   return os << std::string(ucid);
00273 };
00274 
00275 inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueRodIdentifier & urid) {
00276   return os << std::string(urid);
00277 };
00278 
00279 inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueTimIdentifier & utid) {
00280   return os << std::string(utid);
00281 };
00282 
00283 #endif

Generated on Fri Sep 16 18:01:48 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5