Line data Source code
1 : /* File: mock_pin_endpoint.h 2 : * This file is part of the program hardiocore 3 : * Program description : Abstract low level I/O removing direct hardware 4 : * implementation Copyright (C) 2018-2020 - Robin Passama (CNRS / LIRMM) 5 : * Clement Rebut (EPITA / LIRMM) Charles Villard (EPITA / LIRMM). All Right 6 : * reserved. 7 : * 8 : * This software is free software: you can redistribute it and/or modify 9 : * it under the terms of the CeCILL-C license as published by 10 : * the CEA CNRS INRIA, either version 1 11 : * of the License, or (at your option) any later version. 12 : * This software is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : * CeCILL-C License for more details. 16 : * 17 : * You should have received a copy of the CeCILL-C License 18 : * along with this software. If not, it can be found on the official 19 : * website of the CeCILL licenses family (http://www.cecill.info/index.en.html). 20 : */ 21 : /** 22 : * @file test/mock_pin_endpoint.h 23 : * @author Robin Passama 24 : * @brief header file for MockPinEndPoint class. 25 : * @date May 2025 26 : * @ingroup testutils 27 : */ 28 : #pragma once 29 : 30 : #include <map> 31 : #include <string> 32 : #include <memory> 33 : 34 : namespace hardio { 35 : 36 : namespace test { 37 : 38 : struct MockPinEndPoint { 39 : MockPinEndPoint(const std::string& name); 40 60 : ~MockPinEndPoint() = default; 41 : 42 : template <typename T> 43 18 : void set_value(T value) { 44 18 : value_ = static_cast<double>(value); 45 18 : } 46 : 47 : template <typename T> 48 18 : T get_value() const { 49 18 : return static_cast<T>(value_); 50 : } 51 : 52 : const std::string& name() const; 53 : 54 : static std::shared_ptr<MockPinEndPoint> 55 : create_endpoint(const std::string& name); 56 : 57 : static void reset(); 58 : 59 : private: 60 : double value_; 61 : std::string name_; 62 : static std::map<uint64_t, std::shared_ptr<MockPinEndPoint>> endpoints_; 63 : }; 64 : 65 : struct MockPinEndPointAccessor { 66 : 67 : MockPinEndPointAccessor(); 68 66 : virtual ~MockPinEndPointAccessor() = default; 69 : 70 : std::shared_ptr<MockPinEndPoint> endpoint() const; 71 : 72 : bool init(const std::string& name, std::string& reason); 73 : 74 : private: 75 : std::shared_ptr<MockPinEndPoint> endpoint_; 76 : }; 77 : 78 : } // namespace test 79 : } // namespace hardio