On this page
article
peary/hal/Board.hpp
peary/hal/Board.hpp
Hardware Board Base Class. More…
Namespaces
| Name |
|---|
| peary |
| peary::hal |
Classes
| Name | |
|---|---|
| class | peary::hal::Board Base class for a hardware board. |
Detailed Description
Hardware Board Base Class.
Copyright: Copyright (c) 2016-2025 CERN and the Peary Caribou authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only
Source code
#pragma once
#include <map>
#include <memory>
#include <string>
#include "peary/hal/exceptions.hpp"
#include "peary/hal/Resources.hpp"
#include "peary/interfaces/AXI4Lite/axi4lite.hpp"
#include "peary/utils/enum_hash_map.hpp"
#include "peary/utils/type.hpp"
namespace peary::hal {
template <typename R> class Board {
public:
Board() = default;
virtual ~Board() = default;
template <typename T> std::shared_ptr<T> getResource(R res) {
const auto& comp = _resources.find(res);
if(comp != _resources.end()) {
try {
auto ptr = std::dynamic_pointer_cast<T>(comp->second);
if(ptr != nullptr) {
return ptr;
}
} catch(...) {
}
throw InvalidResourceError(magic_enum::enum_name(res), "Invalid resource type");
}
throw InvalidResourceError(magic_enum::enum_name(res), "Resource not found");
}
protected:
template <typename T, typename... Args> void register_resource(R res, Args&&... args) {
if(_resources.find(res) != _resources.end()) {
throw InvalidResourceError(magic_enum::enum_name(res), "Resource already exists");
}
auto resource = std::make_shared<T>(std::forward<Args>(args)...);
resource->setName(magic_enum::enum_name(res));
resource->setType(utils::demangle(typeid(T), false));
_resources.emplace(res, resource);
}
// Resource map of this board, to be populated by child classes
utils::enum_hash_map<R, std::shared_ptr<Resource>> _resources;
};
} // namespace peary::hal
Updated on 2026-01-30 at 22:01:05 +0100