#C++ std::vectorを使用した関数テーブル



```c++:collector.h
#pragma once
#include <array>
#include <vector>

class collector
{
public:
    collector(){}
    ~collector(){}

    void exec();
    static collector& get_instance();

    struct collector_item{
        std::uint8_t (*get_func)(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data);
        std::uint8_t cycle_offset;
        std::uint8_t addr_len;
        std::uint16_t addr_data;
        std::uint8_t read_bytes;
        bool (*store_func)(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result);
    };

    static std::uint8_t get_func_1(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data);
    static std::uint8_t get_func_2(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data);
    static std::uint8_t get_func_3(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data);
    static std::uint8_t get_func_4(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data);

    static bool store_func_1(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result);
    static bool store_func_2(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result);
    static bool store_func_3(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result);
    static bool store_func_4(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result);

};
```

```c++:collector.cpp
#include <iostream>
#include "collector.hpp"

std::vector<collector::collector_item> func_tbl{
    {collector::get_func_1, 0, 1, 0x12, 1, collector::store_func_1},
    {collector::get_func_2, 1, 2, 0x1234, 1, collector::store_func_2},
    {collector::get_func_3, 2, 1, 0x12, 5, collector::store_func_3},
    {collector::get_func_4, 0, 1, 0x12, 1, collector::store_func_4}
};


collector& collector::get_instance()
{
    static collector static_instance;
    return static_instance;
}


void collector::exec()
{
    std::cout << __func__ << std::endl;

    for(collector_item& item : func_tbl)
    {
        std::vector<std::uint8_t> get_data={0,0,0,0,0};
        std::uint8_t result = item.get_func(*this, item, get_data);
        result = item.store_func(*this, item, get_data, result);
    }
}

std::uint8_t collector::get_func_1(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data)
{
    std::cout << __func__ << std::endl;
    data[0] = 1;
    std::cout << __func__ << std::endl;
    return 0;
}
std::uint8_t collector::get_func_2(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data)
{
    std::cout << __func__ << std::endl;
    data[0] = 2;
    return 1;
}
std::uint8_t collector::get_func_3(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data)
{
    std::cout << __func__ << std::endl;
    data[0] = 3;
    return 2;
}
std::uint8_t collector::get_func_4(collector& ins, collector_item& collect, std::vector<std::uint8_t>& data)
{
    std::cout << __func__ << std::endl;
    data[0] = 4;
    return 3;
}


bool collector::store_func_1(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result)
{
    std::cout << __func__ << std::endl;
    printf("data[0] = %d, result = %d\n", data[0], get_func_result);
    return false;
}
bool collector::store_func_2(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result)
{
    std::cout << __func__ << std::endl;
    printf("data[0] = %d, result = %d\n", data[0], get_func_result);
    return false;
}
bool collector::store_func_3(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result)
{
    std::cout << __func__ << std::endl;
    printf("data[0] = %d, result = %d\n", data[0], get_func_result);
    return false;
}
bool collector::store_func_4(collector& ins, collector_item& item, std::vector<std::uint8_t>& data, std::uint8_t get_func_result)
{
    std::cout << __func__ << std::endl;
    printf("data[0] = %d, result = %d\n", data[0], get_func_result);
    return false;
}

```