uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CommaInitializer.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 #ifndef U_CORE_COMMAINITIALIZER_H
27 #define U_CORE_COMMAINITIALIZER_H
28 
29 namespace uLib {
30 
31 // Comma Initializer template ...
32 // ContentT should provide operator[] and resize() methods.
33 // Waiting for Static interface check
34 
35 template < typename ContainerT, typename ContentT >
36 struct CommaInitializer
37 {
38  inline explicit CommaInitializer(ContainerT *container, ContentT s)
39  : container(container)
40  {
41  this->index = 0;
42  container->resize(1);
43  this->container->operator[](0) = s;
44  }
45  inline CommaInitializer & operator, (ContentT s) {
46  this->index++;
47  container->resize(index + 1);
48  this->container->operator[](this->index) = s;
49  return *this;
50  }
51 
52  ContainerT *container;
53  unsigned int index;
54 };
55 
56 
57 // Comma Initializer template for fixed array...
58 // ContentT should provide operator[] and size() methods.
59 // Waiting for Static interface check
60 
61 template < typename ContainerT, typename ContentT >
62 struct CommaInitializerFixed
63 {
64  inline explicit CommaInitializerFixed(ContainerT *container, ContentT s)
65  : container(container)
66  {
67  this->index = 0;
68  this->container->operator[](0) = s;
69  }
70  inline CommaInitializerFixed & operator, (ContentT s) {
71  this->index++;
72  this->container->operator[](this->index) = s;
73  return *this;
74  }
75 
76  ContainerT *container;
77  unsigned int index;
78 };
79 
80 
81 
82 
83 
84 
85 } // uLib
86 
87 
88 
89 #endif // COMMAINITIALIZER_H