Skip to content

TsukiNi22/ai-utils / skills/cpp/cpp-class

cpp-class

Verified

Generate C++ (C++20) .hpp/.cpp files and class architectures in Tsukini's style (Xartania header, indented include guards, INCLUDE/CLASS sections, Pre-Function/Function/Operator/Constructor/Destructor blocks, libutils attributes or standard [[...]]), with empty bodies only (never the logic), then register the .cpp in the CMakeLists.txt. Also creates the main.cpp entry point in the same style. Use whenever the user asks to create, scaffold or add a C++ class, a main / entry point, interface (I*), abstract class (A*), template, struct/Type or Define header, module or set of .hpp/.cpp files.

examples/Scheduler.hpp

View on GitHub
/**************************************************************\

 ██╗  ██╗ █████╗ ██████╗ ████████╗ █████╗ ███╗   ██╗██╗ █████╗
 ╚██╗██╔╝██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗████╗  ██║██║██╔══██╗
  ╚███╔╝ ███████║██████╔╝   ██║   ███████║██╔██╗ ██║██║███████║
  ██╔██╗ ██╔══██║██╔══██╗   ██║   ██╔══██║██║╚██╗██║██║██╔══██║
 ██╔╝ ██╗██║  ██║██║  ██║   ██║   ██║  ██║██║ ╚████║██║██║  ██║
 ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═══╝╚═╝╚═╝  ╚═╝

Edition:
##  @date 21/09/2026 by @author Tsukini

File Name:
##  @file Scheduler.hpp

File Description:
##  Scheduler definition
\**************************************************************/

#ifndef SCHEDULER_H
    #define SCHEDULER_H

    //----------------------------------------------------------------//
    /* INCLUDE */

    /* type */
    #include "../security/observer/Observer.hpp"    // utils::security::observer::Observer
    #include "../attribute/Attribute.hpp"           // _cold, _hot, _unlikely
    #include "IdHandler.hpp"                        // utils::system::IdHandler
    #include <condition_variable>                   // std::condition_variable_any
    #include <unordered_map>                        // std::unordered_map
    #include <type_traits>                          // std::is_invocable_r_v
    #include <cstddef>                              // std::size_t
    #include <thread>                               // std::jthread
    #include <chrono>                               // std::chrono::milliseconds
    #include <vector>                               // std::vector
    #include <mutex>                                // std::mutex, std::unique_lock, std::lock_guard

namespace utils::system { // namespace start
//----------------------------------------------------------------//
/* CLASS */

class Scheduler: private utils::security::observer::Observer<"Scheduler"> {
    private:
        utils::system::IdHandler<std::size_t> _idHandler;

        /* destruction */
        std::mutex _lock;
        std::vector<std::size_t> _finished;

        /* tasks */
        std::unordered_map<std::size_t, std::jthread> _tasks;

        // ---------- Pre-Function -------- //
        void clear_(void); // clear finished task

        // ------------ Function ---------- //
        _cold inline void cancel_(std::size_t id) {this->_tasks.erase(id); this->_idHandler.free(id);};

    public:
        // ---------- Pre-Function -------- //
        void cancel(std::size_t id); // cancel given task

        // ------------ Function ---------- //
        _cold inline void cancel(void) {this->_tasks.clear(); this->_finished.clear(); this->_idHandler.free();};
        template<typename Fn>
        _hot std::size_t schedule(std::chrono::milliseconds delay, const Fn& fn) // schedule a new task
        {
            static_assert(std::is_invocable_r_v<void, Fn>, "Fn must be callable with no arguments (signature: void(void))");
            this->clear_();

            // Get a new id
            std::size_t id = this->_idHandler.allocate();

            // Setup the new thread
            this->_tasks.emplace(id, std::jthread([this, id, delay, fn](std::stop_token stoken) {
                // Setup condition_variable_any
                std::mutex mutex;
                std::unique_lock<std::mutex> cvlock(mutex);
                std::condition_variable_any cv;

                // Wait until timeout or cancel trigger
                (void)cv.wait_for(cvlock, stoken, delay, [](void) {return false;});

                if (!stoken.stop_requested()) _likely {fn();}

                // Signal the ending of the task
                std::lock_guard lock(this->_lock);
                this->_finished.push_back(id);
            }));

            return id;
        };

        // ------------ Operator ---------- //
        Scheduler& operator=(const Scheduler& other) = delete;
        Scheduler& operator=(Scheduler&& other) = delete;

        // ---------- Constructor --------- //
        Scheduler() = default;
        Scheduler(const Scheduler& other) = delete;
        Scheduler(Scheduler&& other) = delete;

        // ----------- Destructor --------- //
        ~Scheduler() = default;
};

} // namespace end
#endif /* SCHEDULER_H */
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 192kUpdated Claude CodeCodexVerifiedInstall