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