Addressing.h

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

Generated on Mon Feb 6 14:01:16 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6