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
ServerTemplates.cc
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 PDB_SERVER_TEMP_CC
20 #define PDB_SERVER_TEMP_CC
21 
22 #include "Handle.h"
23 #include "PDBServer.h"
24 #include "ServerFunctionality.h"
25 #include <memory>
26 
27 namespace pdb {
28 
29 template <class Functionality, class... Args>
30 void PDBServer::addFunctionality(Args&&... args) {
31 
32  // first, get the name of this type
33  std::string myType = getTypeName<Functionality>();
34 
35  // and remember him... map him to a particular index in the list of functionalities
36  if (allFunctionalityNames.count(myType) == 1) {
37  std::cerr << "BAD! You can't add the same functionality twice.\n";
38  }
40 
41  // then create the functionality
42  shared_ptr<ServerFunctionality> whichFunctionality = make_shared<Functionality>(args...);
43  allFunctionalities.push_back(whichFunctionality);
44 
46 }
47 
48 template <class Functionality>
49 Functionality& PDBServer::getFunctionality() {
50 
51  // first, figure out which index we are
52  static int whichIndex = -1;
53  if (whichIndex == -1) {
54  std::string myType = getTypeName<Functionality>();
55  whichIndex = allFunctionalityNames[myType];
56  }
57 
58  // and now, return the functionality
59  return *((Functionality*)allFunctionalities[whichIndex].get());
60 }
61 }
62 
63 #endif
std::map< std::string, int > allFunctionalityNames
Definition: PDBServer.h:163
std::vector< shared_ptr< ServerFunctionality > > allFunctionalities
Definition: PDBServer.h:166
Functionality & getFunctionality()
void addFunctionality(Args &&...args)
void registerHandlersFromLastFunctionality()
Definition: PDBServer.cc:374