PSEvt/include/AliasMap.h

Go to the documentation of this file.
00001 #ifndef PSEVT_ALIASMAP_H
00002 #define PSEVT_ALIASMAP_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: AliasMap.h 11492 2016-03-16 04:30:13Z cpo@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class AliasMap.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 #include <map>
00017 #include <vector>
00018 #include <string>
00019 
00020 //----------------------
00021 // Base Class Headers --
00022 //----------------------
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "pdsdata/xtc/Src.hh"
00028 
00029 //------------------------------------
00030 // Collaborating Class Declarations --
00031 //------------------------------------
00032 
00033 //              ---------------------
00034 //              -- Class Interface --
00035 //              ---------------------
00036 
00037 namespace PSEvt {
00038 
00039 /// @addtogroup PSEvt
00040 
00041 /**
00042  *  @ingroup PSEvt
00043  *
00044  *  @brief Implementation of the alias map used by proxy dictionaries.
00045  *
00046  *  Alias map is a bi-directional mapping between alias name and corresponding
00047  *  Pds::Src instance.
00048  *
00049  *  @note This software was developed for the LCLS project.  If you use all or 
00050  *  part of it, please give an appropriate acknowledgment.
00051  *
00052  *  @version $Id: AliasMap.h 11492 2016-03-16 04:30:13Z cpo@SLAC.STANFORD.EDU $
00053  *
00054  *  @author Andy Salnikov
00055  */
00056 
00057 class AliasMap {
00058 public:
00059 
00060   /// Default constructor makes empty alias map
00061   AliasMap();
00062 
00063   // Destructor
00064   ~AliasMap();
00065 
00066   /// Add one more alias to the map
00067   void add(const std::string& alias, const Pds::Src& src);
00068 
00069   /// remove all aliases
00070   void clear();
00071 
00072   /**
00073    *  @brief Find matching Src for given alias name.
00074    *
00075    *  If specified alias name does not exist in the map then
00076    *  default-constructed instance of Src will be returned.
00077    *
00078    *  @param[in] alias    Alias name
00079    *  @return  Src instance
00080    */
00081   Pds::Src src(const std::string& alias) const;
00082 
00083   /**
00084    *  @brief Find matching alias name for given Src.
00085    *
00086    *  If specified Src does not exist in the map then
00087    *  empty string will be returned.
00088    *
00089    *  @param[in] src   Src instance
00090    *  @return  Alias string (possibly empty)
00091    */
00092   std::string alias(const Pds::Src& src) const;
00093 
00094   void addsrc(const Pds::Src& name);
00095 
00096   const std::vector<Pds::Src>& srcs();
00097 
00098 protected:
00099 
00100 private:
00101 
00102   // Special compare functor which compares Src instances, we need to ignore
00103   // process ID part of Src.
00104   struct SrcCmp {
00105     bool operator()(const Pds::Src& lhs, const Pds::Src& rhs) const;
00106   };
00107   
00108   std::map<std::string, Pds::Src> m_alias2src;         ///< Mapping from alias name to Src
00109   std::map<Pds::Src, std::string, SrcCmp> m_src2alias; ///< Mapping from Src to alias name
00110   std::vector<Pds::Src> m_srcs;
00111 
00112 };
00113 
00114 } // namespace PSEvt
00115 
00116 #endif // PSEVT_ALIASMAP_H

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7