FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_SharedIDs.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2009 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _fei_SharedIDs_hpp_
10 #define _fei_SharedIDs_hpp_
11 
12 #include <fei_macros.hpp>
13 
14 #include <vector>
15 #include <set>
16 #include <map>
17 
18 namespace fei {
19 
21  template<typename T>
22  class SharedIDs {
23  public:
26  : sharedIDs_(), owningProcs_()
27  {}
28 
30  SharedIDs(const SharedIDs<T>& src)
31  : sharedIDs_(src.sharedIDs_), owningProcs_(src.owningProcs_)
32  {}
33 
35  virtual ~SharedIDs() {}
36 
38  typedef std::map<T,std::set<int> > map_type;
39 
45  void addSharedID(const T& ID, size_t numSharingProcs, const int* sharingProcs)
46  {
47  typename map_type::iterator iter = sharedIDs_.find(ID);
48  if (iter == sharedIDs_.end()) {
49  iter = sharedIDs_.insert(std::make_pair(ID,std::set<int>())).first;
50  }
51  for(size_t i=0; i<numSharingProcs; ++i) {
52  iter->second.insert(sharingProcs[i]);
53  }
54  }
55 
57  map_type& getSharedIDs() { return( sharedIDs_ ); }
58 
60  const map_type& getSharedIDs() const { return( sharedIDs_ ); }
61 
64  std::vector<int>& getOwningProcs() { return( owningProcs_ ); }
65 
68  const std::vector<int>& getOwningProcs() const { return( owningProcs_ ); }
69 
70  private:
71  map_type sharedIDs_;
72  std::vector<int> owningProcs_;
73  };
74 
75 } //namespace fei
76 
77 #endif // _fei_SharedIDs_hpp_
78 
std::vector< int > & getOwningProcs()
std::map< T, std::set< int > > map_type
map_type & getSharedIDs()
SharedIDs(const SharedIDs< T > &src)
const map_type & getSharedIDs() const
void addSharedID(const T &ID, size_t numSharingProcs, const int *sharingProcs)
const std::vector< int > & getOwningProcs() const
virtual ~SharedIDs()