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
Supervisor.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 SUPERVISOR_H
20 #define SUPERVISOR_H
21 
22 #include "Object.h"
23 #include "PDBVector.h"
24 #include "PDBString.h"
25 #include "Handle.h"
26 #include "Employee.h"
27 #include "ExportableObject.h"
28 
29 // PRELOAD %Supervisor%
30 
31 namespace pdb {
32 
33 class Supervisor : public ExportableObject {
34 
35 public:
38 
40 
43 
44  Supervisor(std::string name, int age) {
45  me = makeObject<Employee>(name, age);
46  }
47 
48  Supervisor(std::string name, int age, std::string department, double salary) {
49  me = makeObject<Employee>(name, age, department, salary);
50  }
51 
53  return myGuys[who];
54  }
55 
57  return myGuys.size();
58  }
59 
61  return me->department;
62  }
63 
65  return me->getName();
66  }
67 
68  void addEmp(Handle<Employee>& addMe) {
69  myGuys.push_back(addMe);
70  }
71 
73  for (int i = 0; i < myGuys.size(); i++) {
74  if (myGuys[i]->getName() == "Steve Stevens")
75  return myGuys[i];
76  }
77  return nullptr;
78  }
79 
81  return me;
82  }
83 
84  void print() final {
85  me->print();
86  std::cout << "\nPlus have " << myGuys.size() << " employees.\n";
87  /*if (myGuys.size () > 0) {
88  std :: cout << "\t (One is ";
89  myGuys[0]->print ();
90  std :: cout << ")\n";
91  }*/
92  for (int i = 0; i < myGuys.size(); i++) {
93  std::cout << "emp " << i << ": ";
94  myGuys[i]->print();
95  std::cout << " ";
96  }
97  }
98 
99 
100  std::string toSchemaString(std::string format) override {
101  return "";
102  }
103 
104  std::string toValueString(std::string format) override {
105  if (format == "json") {
106  char buffer[1024];
107  sprintf(
108  buffer,
109  "{\"name\":\"%s\",\"age\":%d,\"salary\":%f,\"department\":\"%s\",\"employees\":[",
110  me->getName()->c_str(),
111  me->getAge(),
112  me->getSalary(),
113  me->department.c_str());
114  std::string ret = std::string(buffer);
115  if (myGuys.size() > 0) {
116  char buffer[1024];
117  sprintf(buffer,
118  "{\"name\":\"%s\",\"age\":%d,\"salary\":%f,\"department\":\"%s\"}",
119  myGuys[0]->getName()->c_str(),
120  myGuys[0]->getAge(),
121  myGuys[0]->getSalary(),
122  myGuys[0]->department.c_str());
123  ret += std::string(buffer);
124  }
125  for (int i = 1; i < myGuys.size(); i++) {
126  char buffer[1024];
127  sprintf(buffer,
128  ",{\"name\":\"%s\",\"age\":%d,\"salary\":%f,\"department\":\"%s\"}",
129  myGuys[i]->getName()->c_str(),
130  myGuys[i]->getAge(),
131  myGuys[i]->getSalary(),
132  myGuys[i]->department.c_str());
133  ret += std::string(buffer);
134  }
135  ret += std::string("]}\n");
136  return ret;
137  } else {
138  return "";
139  }
140  }
141 
142 
143  std::vector<std::string> getSupportedFormats() override {
144  std::vector<std::string> ret;
145  ret.push_back("json");
146  return ret;
147  }
148 };
149 }
150 
151 #endif
#define ENABLE_DEEP_COPY
Definition: DeepCopy.h:52
Handle< Employee > & getMe()
Definition: Supervisor.h:80
Supervisor(std::string name, int age, std::string department, double salary)
Definition: Supervisor.h:48
void addEmp(Handle< Employee > &addMe)
Definition: Supervisor.h:68
void print() final
Definition: Supervisor.h:84
int getNumEmployees()
Definition: Supervisor.h:56
Handle< Employee > me
Definition: Supervisor.h:36
Handle< Employee > & getEmp(int who)
Definition: Supervisor.h:52
String getDepartment()
Definition: Supervisor.h:60
Handle< String > getName()
Definition: Supervisor.h:64
std::string toValueString(std::string format) override
Definition: Supervisor.h:104
Supervisor(std::string name, int age)
Definition: Supervisor.h:44
Vector< Handle< Employee > > myGuys
Definition: Supervisor.h:37
Handle< Employee > getSteve()
Definition: Supervisor.h:72
std::string toSchemaString(std::string format) override
Definition: Supervisor.h:100
ENABLE_DEEP_COPY ~Supervisor()
Definition: Supervisor.h:41
std::vector< std::string > getSupportedFormats() override
Definition: Supervisor.h:143