Directory: | ./ |
---|---|
File: | src/problem-solver-map.cc |
Date: | 2024-12-13 15:50:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 24 | 43 | 55.8% |
Branches: | 16 | 66 | 24.2% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2019, 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 | #include <hpp/corbaserver/problem-solver-map.hh> | ||
30 | #include <hpp/core/problem-solver.hh> | ||
31 | |||
32 | namespace hpp { | ||
33 | namespace corbaServer { | ||
34 | 8 | ProblemSolverMap::ProblemSolverMap(core::ProblemSolverPtr_t init, | |
35 | 8 | const std::string& name) | |
36 |
5/10✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 8 times.
✗ Branch 16 not taken.
|
8 | : selected_(name), map_(new ProblemMap_t), mutex_(new mutex_t) { |
37 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | add(selected_, init); |
38 | 8 | } | |
39 | |||
40 | 8 | ProblemSolverMap::ProblemSolverMap(const ProblemSolverMap& other) | |
41 | 8 | : selected_(other.selected_), map_(other.map_), mutex_(other.mutex_) {} | |
42 | |||
43 | ✗ | core::ProblemSolverPtr_t ProblemSolverMap::operator->() { return selected(); } | |
44 | |||
45 | ✗ | ProblemSolverMap::operator core::ProblemSolverPtr_t() { return selected(); } | |
46 | |||
47 | 106 | core::ProblemSolverPtr_t ProblemSolverMap::selected() const { | |
48 | 106 | return get(selected_); | |
49 | } | ||
50 | |||
51 | 106 | core::ProblemSolverPtr_t ProblemSolverMap::get(const std::string& name) const { | |
52 |
1/2✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | mutex_t::scoped_lock lock(*mutex_); |
53 |
1/2✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | ProblemMap_t::const_iterator it = map_->find(name); |
54 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 106 times.
|
106 | if (it == map_->end()) |
55 | ✗ | throw std::invalid_argument("Could not find ProblemSolver named " + name); | |
56 | 212 | return it->second; | |
57 | 106 | } | |
58 | |||
59 | 8 | bool ProblemSolverMap::has(const std::string& name) const { | |
60 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | mutex_t::scoped_lock lock(*mutex_); |
61 | // ProblemMap_t::const_iterator it = map_.find (name); | ||
62 | // return it != map_.end (); | ||
63 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
16 | return map_->end() != map_->find(name); |
64 | 8 | } | |
65 | |||
66 | ✗ | void ProblemSolverMap::selected(const std::string& name) { | |
67 | ✗ | if (!has(name)) | |
68 | ✗ | throw std::invalid_argument("Could not find ProblemSolver named " + name); | |
69 | ✗ | mutex_t::scoped_lock lock(*mutex_); | |
70 | ✗ | selected_ = name; | |
71 | } | ||
72 | |||
73 | 8 | void ProblemSolverMap::add(const std::string& name, | |
74 | core::ProblemSolverPtr_t ps) { | ||
75 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
|
8 | if (has(name)) |
76 | ✗ | throw std::invalid_argument("ProblemSolver named " + name + | |
77 | ✗ | " already exists"); | |
78 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | mutex_t::scoped_lock lock(*mutex_); |
79 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
8 | map_->insert(std::make_pair(name, ps)); |
80 | 8 | } | |
81 | |||
82 | ✗ | void ProblemSolverMap::remove(const std::string& name) { | |
83 | ✗ | mutex_t::scoped_lock lock(*mutex_); | |
84 | ✗ | map_->erase(name); | |
85 | } | ||
86 | |||
87 | ✗ | void ProblemSolverMap::replaceSelected(core::ProblemSolverPtr_t ps) { | |
88 | ✗ | mutex_t::scoped_lock lock(*mutex_); | |
89 | ✗ | ProblemMap_t::iterator it = map_->find(selected_); | |
90 | ✗ | assert(it != map_->end()); | |
91 | ✗ | delete it->second; | |
92 | ✗ | it->second = ps; | |
93 | } | ||
94 | } // end of namespace corbaServer. | ||
95 | } // end of namespace hpp. | ||
96 |