A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DepartmentEmployees.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef DEPARTMENT_EMPLOYEES_H
20 #define DEPARTMENT_EMPLOYEES_H
21 
22 #include "Object.h"
23 #include "PDBString.h"
24 #include "Employee.h"
25 #include "PDBMap.h"
26 #include "PDBVector.h"
27 
28 // PRELOAD %DepartmentEmployees%
29 
30 namespace pdb {
31 
32 class DepartmentEmployees : public Object {
33 
34 public:
36 
38 
39  String departmentName; // the name of the department
41  employees; // for each supervisor in this department, the list of employees
43 
44 
46  return departmentName;
47  }
48 
50  return employees;
51  }
52 
53  void print() {
54  std::cout << "Department: " << departmentName << std::endl;
55  auto iter = employees.begin();
56  while (iter != employees.end()) {
57  std::cout << "----Supervisor: " << (*iter).key << std::endl;
58  std::cout << "----NumEmployees: " << (*iter).value.size() << std::endl;
59  for (int i = 0; i < (*iter).value.size(); i++) {
60  std::cout << i << ": ";
61  (((*iter).value)[i])->print();
62  std::cout << ";";
63  }
64  std::cout << std::endl;
65  ++iter;
66  }
67  }
68 };
69 
70 
73  auto iter = rhs.begin();
74  while (iter != rhs.end()) {
75  String myKey = (*iter).key;
76  if (lhs.count(myKey) == 0) {
77  try {
78  lhs[myKey] = (*iter).value;
79  } catch (NotEnoughSpace& n) {
80  // std :: cout << "not enough space when inserting new pair" << std :: endl;
81  lhs.setUnused(myKey);
82  throw n;
83  }
84  } else {
85 
86  size_t mySize = lhs[myKey].size();
87  size_t otherSize = (*iter).value.size();
88 
89 
90  // std :: cout << "mySize is " << mySize << " and otherSize is " << otherSize << std ::
91  // endl;
92  for (size_t i = mySize; i < mySize + otherSize; i++) {
93  try {
94 
95  lhs[myKey].push_back((*iter).value[i - mySize]);
96 
97  } catch (NotEnoughSpace& n) {
98 
99  // std :: cout << i << ": not enough space when updating value by pushing back:
100  // " << lhs[myKey].size() << std :: endl;
101  throw n;
102  }
103  }
104  // std :: cout << "now my size is " << (*lhs)[myKey].size() << std :: endl;
105  }
106  ++iter;
107  }
108  return lhs;
109 }
110 }
111 
112 #endif
#define ENABLE_DEEP_COPY
Definition: DeepCopy.h:52
Handle< Map< String, Vector< int > > > & operator+(Handle< Map< String, Vector< int >>> &lhs, Handle< Map< String, Vector< int >>> &rhs)
ENABLE_DEEP_COPY String & getKey()
Map< String, Vector< Handle< Employee > > > & getValue()
Map< String, Vector< Handle< Employee > > > employees