src/lib/ProxyVector.h
branchv_0
changeset 24 114810ee2386
equal deleted inserted replaced
23:8941a679299f 24:114810ee2386
       
     1 /**
       
     2  * Relational pipes
       
     3  * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, version 3 of the License.
       
     8  *
       
     9  * This program 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
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    16  */
       
    17 #pragma once
       
    18 
       
    19 #include <memory>
       
    20 
       
    21 namespace relpipe {
       
    22 namespace in {
       
    23 namespace asn1 {
       
    24 namespace lib {
       
    25 
       
    26 template <typename Class>
       
    27 class ProxyVector : public std::vector<std::shared_ptr<Class>> {
       
    28 public:
       
    29 
       
    30 	/**
       
    31 	 * Call given method on all instances.
       
    32 	 *
       
    33 	 * @param method a method of Class
       
    34 	 * @param arguments arguments of the method
       
    35 	 */
       
    36 	template<typename Method, typename... Arguments> void forward(Method method, Arguments&&... arguments) {
       
    37 		for (auto& h : * this) {
       
    38 			// TODO: optionally handle/collect exceptions
       
    39 			(h.get()->*method)(arguments...);
       
    40 		}
       
    41 	}
       
    42 };
       
    43 
       
    44 }
       
    45 }
       
    46 }
       
    47 }