FEI Version of the Day
fei_SharedIDs.hpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2009 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_SharedIDs_hpp_
00010 #define _fei_SharedIDs_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 
00014 #include <vector>
00015 #include <set>
00016 #include <map>
00017 
00018 namespace fei {
00019 
00021   template<typename T>
00022   class SharedIDs {
00023   public:
00025     SharedIDs()
00026       : sharedIDs_(), owningProcs_()
00027     {}
00028 
00030     SharedIDs(const SharedIDs<T>& src)
00031       : sharedIDs_(src.sharedIDs_), owningProcs_(src.owningProcs_)
00032     {}
00033 
00035     virtual ~SharedIDs() {}
00036 
00038     typedef std::map<T,std::set<int> > map_type;
00039 
00045     void addSharedID(const T& ID, size_t numSharingProcs, const int* sharingProcs)
00046     {
00047       typename map_type::iterator iter = sharedIDs_.find(ID);
00048       if (iter == sharedIDs_.end()) {
00049         iter = sharedIDs_.insert(std::make_pair(ID,std::set<int>())).first;
00050       }
00051       for(size_t i=0; i<numSharingProcs; ++i) {
00052         iter->second.insert(sharingProcs[i]);
00053       }
00054     }
00055 
00057     map_type& getSharedIDs() { return( sharedIDs_ ); }
00058 
00060     const map_type& getSharedIDs() const { return( sharedIDs_ ); }
00061 
00064     std::vector<int>& getOwningProcs() { return( owningProcs_ ); }
00065 
00068     const std::vector<int>& getOwningProcs() const { return( owningProcs_ ); }
00069 
00070   private:
00071     map_type sharedIDs_;
00072     std::vector<int> owningProcs_;
00073   };
00074 
00075 } //namespace fei
00076 
00077 #endif // _fei_SharedIDs_hpp_
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends