libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
batch_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2004 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE {
20 
21 template<class Colln, unsigned long I> inline
22 typename front_batch<Colln, I>::value_ret_type
23 front_batch<Colln, I>::pop_front_nochk_nolk() noexcept(true) {
24 // TODO Dunno why the partial specialisation doesn't seem to work...
25  if (max_size>1) {
26  value_ret_type ret;
27  typename value_ret_type::size_type i=0;
28  do {
29  ret[i]=std::move(this->colln().front());
30  assert(!this->colln().empty());
31  this->have_work.remove();
32  this->colln().pop_front();
33  } while (++i<ret.size() && !this->colln().empty());
34  std::fill_n(ret.begin()+i, ret.size()-i, typename value_ret_type::value_type());
35  return ret;
36  } else {
37  return base_t::pop_front_nochk_nolk();
38  }
39 }
40 
41 template<class Colln> inline
42 typename front_batch<Colln, 1UL>::value_ret_type
43 front_batch<Colln, 1UL>::pop_front_nochk_nolk() noexcept(true) {
44  return base_t::pop_front_nochk_nolk();
45 }
46 
47 /* TODO Implement these properly.
48 template<class Colln, unsigned long I> inline void
49 back_batch<Colln, I>::push_back(const value_type &data_item) noexcept(false) {
50  if (!this->empty()) {
51  const typename container_type::write_lock_type lk(this->push_lock(), container_type::lock_traits::infinite_timeout());
52  value_type &agg_data_item=this->back_nolk();
53  if (agg_data_item->size()<max_size) {
54  agg_data_item->reserve(max_size);
55  agg_data_item->insert(agg_data_item->end(), data_item->begin(), data_item->end());
56  } else {
57  container_type::push_back_nolk(data_item);
58  }
59  } else {
60  container_type::push_back_nolk(data_item);
61  }
62 }
63 
64 template<class Colln, unsigned long I> inline void
65 back_batch<Colln, I>::push(const value_type &data_item) noexcept(false) {
66  if (!this->empty()) {
67  const typename container_type::write_lock_type lk(this->push_lock(), container_type::lock_traits::infinite_timeout());
68  value_type &agg_data_item=this->back_nolk();
69  if (agg_data_item->size()<max_size) {
70  agg_data_item->reserve(max_size);
71  agg_data_item->insert(agg_data_item->end(), data_item->begin(), data_item->end());
72  } else {
73  container_type::push_nolk(data_item);
74  }
75  } else {
76  container_type::push_nolk(data_item);
77  }
78 }
79 */
80 template<class Colln> inline void
81 back_batch<Colln, 1UL>::push_back(const value_type &data_item) noexcept(false) {
82  base_t::push_back(data_item);
83 }
84 
85 template<class Colln> inline void
86 back_batch<Colln, 1UL>::push_back(value_type &&data_item) noexcept(false) {
87  base_t::push_back(data_item);
88 }
89 
90 template<class Colln> inline void
91 back_batch<Colln, 1UL>::push(const value_type &data_item) noexcept(false) {
92  base_t::push(data_item);
93 }
94 
95 template<class Colln> inline void
96 back_batch<Colln, 1UL>::push(value_type &&data_item) noexcept(false) {
97  base_t::push(data_item);
98 }
99 
100 } }