libluna: Document Attributes.h and Badge.h

This commit is contained in:
apio 2023-08-23 13:24:28 +02:00
parent b8e70996c3
commit 24f9dd22ec
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,12 @@
/**
* @file Attributes.h
* @author apio (cloudapio.eu)
* @brief Macro wrappers around GCC attributes.
*
* @copyright Copyright (c) 2022-2023, the Luna authors.
*
*/
#pragma once #pragma once
#define _weak __attribute__((weak)) #define _weak __attribute__((weak))

View File

@ -1,8 +1,33 @@
/**
* @file Badge.h
* @author apio (cloudapio.eu)
* @brief A simple way to control who can call functions.
*
* @copyright Copyright (c) 2022-2023, the Luna authors.
*
*/
#pragma once #pragma once
/**
* @brief A struct that can only be constructed by one type, used to control access to functions/methods.
*
* Example: There is a private method FooClass::foo() that you want to be callable by BarClass without making it a
* friend.
*
* So, make FooClass::foo() public and make it take a Badge<BarClass> which will only be constructible by BarClass, thus
* limiting the method even though it is public.
*
* @tparam T The type that can construct this badge.
*/
template <class T> struct Badge template <class T> struct Badge
{ {
private: private:
/**
* @brief Construct a new Badge.
*
* This can only be done by the type T.
*/
constexpr Badge() = default; constexpr Badge() = default;
Badge(const Badge<T>&) = delete; Badge(const Badge<T>&) = delete;