Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2016, Joseph Mirabel |
2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
// Redistribution and use in source and binary forms, with or without |
6 |
|
|
// modification, are permitted provided that the following conditions are |
7 |
|
|
// met: |
8 |
|
|
// |
9 |
|
|
// 1. Redistributions of source code must retain the above copyright |
10 |
|
|
// notice, this list of conditions and the following disclaimer. |
11 |
|
|
// |
12 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
// notice, this list of conditions and the following disclaimer in the |
14 |
|
|
// documentation and/or other materials provided with the distribution. |
15 |
|
|
// |
16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
27 |
|
|
// DAMAGE. |
28 |
|
|
|
29 |
|
|
#ifndef HPP_CORBASERVER_PROBLEM_SOLVER_MAP_HH |
30 |
|
|
#define HPP_CORBASERVER_PROBLEM_SOLVER_MAP_HH |
31 |
|
|
#include <boost/thread/mutex.hpp> |
32 |
|
|
#include <map> |
33 |
|
|
|
34 |
|
|
#include "hpp/corbaserver/config.hh" |
35 |
|
|
#include "hpp/corbaserver/fwd.hh" |
36 |
|
|
#include "hpp/core/fwd.hh" |
37 |
|
|
|
38 |
|
|
namespace hpp { |
39 |
|
|
namespace corbaServer { |
40 |
|
|
class HPP_CORBASERVER_DLLAPI ProblemSolverMap { |
41 |
|
|
public: |
42 |
|
|
typedef std::map<std::string, core::ProblemSolverPtr_t> ProblemMap_t; |
43 |
|
|
typedef shared_ptr<ProblemMap_t> ProblemMapPtr_t; |
44 |
|
|
typedef boost::mutex mutex_t; |
45 |
|
|
typedef shared_ptr<mutex_t> mutexPtr_t; |
46 |
|
|
|
47 |
|
|
ProblemSolverMap(core::ProblemSolverPtr_t init, |
48 |
|
|
const std::string& name = "default"); |
49 |
|
|
|
50 |
|
|
ProblemSolverMap(const ProblemSolverMap& map); |
51 |
|
|
|
52 |
|
|
core::ProblemSolverPtr_t operator->(); |
53 |
|
|
operator core::ProblemSolverPtr_t(); |
54 |
|
|
|
55 |
|
|
core::ProblemSolverPtr_t selected() const; |
56 |
|
|
core::ProblemSolverPtr_t get(const std::string& name) const; |
57 |
|
|
void selected(const std::string& name); |
58 |
|
|
|
59 |
|
|
bool has(const std::string& name) const; |
60 |
|
|
void add(const std::string& name, core::ProblemSolverPtr_t ps); |
61 |
|
|
void remove(const std::string& name); |
62 |
|
|
void replaceSelected(core::ProblemSolverPtr_t ps); |
63 |
|
|
|
64 |
|
|
template <typename ReturnType> |
65 |
|
✗ |
ReturnType keys() const { |
66 |
|
✗ |
mutex_t::scoped_lock lock(*mutex_); |
67 |
|
✗ |
ReturnType l; |
68 |
|
✗ |
for (ProblemMap_t::const_iterator it = map_->begin(); it != map_->end(); |
69 |
|
✗ |
++it) |
70 |
|
✗ |
l.push_back(it->first); |
71 |
|
✗ |
return l; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
const std::string& selectedName() const { return selected_; } |
75 |
|
|
|
76 |
|
|
private: |
77 |
|
|
std::string selected_; |
78 |
|
|
ProblemMapPtr_t map_; |
79 |
|
|
mutexPtr_t mutex_; |
80 |
|
|
}; |
81 |
|
|
} // end of namespace corbaServer. |
82 |
|
|
} // end of namespace hpp. |
83 |
|
|
|
84 |
|
|
#endif //! HPP_CORBASERVER_PROBLEM_SOLVER_MAP_HH |
85 |
|
|
|