|
libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
|
In-process command interpreter used by ConsoleWindow. More...
#include <Console.h>
Public Member Functions | |
| Console () | |
| ~Console () | |
| int32_t | Run (const std::string &command, std::string *output) |
| Registers built-in commands. Called by Component::Init(). | |
| bool | HasCommand (const std::string &command) |
| Returns true if a command with the given name is registered. | |
| void | AddCommand (const std::string &command, CommandEntry entry) |
| Registers a new command. | |
| std::string | BuildUsage (const std::string &command) |
| Builds a usage string from the command's argument list. | |
| std::string | BuildUsage (const CommandEntry &entry) |
| Builds a usage string directly from a CommandEntry. | |
| CommandEntry & | GetCommand (const std::string &command) |
| Returns a reference to the CommandEntry for the given command name. | |
| std::map< std::string, CommandEntry > & | GetCommands () |
| Returns the full command registry (name → entry map). | |
Public Member Functions inherited from Ship::Component | |
| Component (const std::string &name, std::shared_ptr< Context > context=nullptr) | |
| Constructs a Component with the given name. | |
| virtual | ~Component () |
| void | Init (const nlohmann::json &initArgs=nlohmann::json::object()) |
| Performs one-time initialization of this component. | |
| bool | IsInitialized () const |
| Returns true once Init() (or MarkInitialized()) has completed successfully. | |
| const std::string & | GetName () const |
| Returns the name of this Component. | |
| std::string | ToString () const |
| Returns a human-readable string representation (e.g. "Name (id)"). | |
| std::string | ToTreeString (int depth=0) const |
| Returns a human-readable tree representation of this component and its children. | |
| operator std::string () const | |
| Conversion operator to std::string; equivalent to ToString(). | |
| ParentComponentList & | GetParents () |
| Returns a mutable reference to the parent list. | |
| const ParentComponentList & | GetParents () const |
| Returns a const reference to the parent list. | |
| ComponentList & | GetChildren () |
| Returns a mutable reference to the child list. | |
| const ComponentList & | GetChildren () const |
| Returns a const reference to the child list. | |
| virtual std::shared_ptr< Component > | TryGetSharedComponent () noexcept |
| Returns a shared_ptr to this Component when available, otherwise nullptr. | |
| virtual std::shared_ptr< Component > | GetSharedComponent () |
| Returns a shared_ptr to this Component via the correct enable_shared_from_this base. | |
| template<typename T > | |
| bool | HasInChildren () const |
| Checks whether any descendant Component matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< T > | GetFirstInChildren () const |
| Returns the first descendant that matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< std::vector< std::shared_ptr< T > > > | GetInChildren () const |
| Returns all descendants that match type T via BFS. | |
| template<typename T > | |
| bool | HasInParents () const |
| Checks whether any ancestor Component matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< T > | GetFirstInParents () const |
| Returns the first ancestor that matches type T via BFS. | |
| template<typename T > | |
| std::shared_ptr< std::vector< std::shared_ptr< T > > > | GetInParents () const |
| Returns all ancestors that match type T via BFS. | |
Public Member Functions inherited from Ship::Part | |
| Part () | |
| Constructs a Part and assigns it a unique ID. | |
| Part (std::shared_ptr< Context > context) | |
| Constructs a Part with an explicit Context reference and unique ID. | |
| virtual | ~Part ()=default |
| uint64_t | GetId () const |
| Returns the unique identifier for this Part. | |
| bool | operator== (const Part &other) const |
| Compares two Parts for equality by their unique IDs. | |
| std::shared_ptr< Context > | GetContext () const |
| Returns the Context this Part belongs to, or nullptr if unset. | |
| void | SetContext (std::shared_ptr< Context > ctx) |
| Sets the Context this Part belongs to. | |
Protected Member Functions | |
| void | OnInit (const nlohmann::json &initArgs=nlohmann::json::object()) override |
| Registers built-in commands. Called automatically by Component::Init(). | |
Protected Member Functions inherited from Ship::Component | |
| void | MarkInitialized () |
| Marks this component as initialized without going through Init(). | |
| template<typename T > | |
| std::shared_ptr< T > | RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const |
| Returns a cached dependency after validating it exists and is initialized. | |
Protected Member Functions inherited from Ship::Part | |
| virtual void | OnAdded (bool forced) |
| Called after this Part has been added to a PartList. | |
| virtual void | OnRemoved (bool forced) |
| Called after this Part has been removed from a PartList. | |
In-process command interpreter used by ConsoleWindow.
Console stores a registry of named commands and dispatches input strings to the matching handler. Built-in commands (help, bind, set, get, …) are registered by ConsoleWindow during its initialization.
Required Context children (looked up at runtime):
Context::GetChildren().GetFirst<Console>() to obtain the Console when executing commands. This is satisfied automatically once Console is added to the Context.Obtain the instance from Context::GetChildren().GetFirst<Console>().
| Ship::Console::Console | ( | ) |
| Ship::Console::~Console | ( | ) |
| void Ship::Console::AddCommand | ( | const std::string & | command, |
| CommandEntry | entry | ||
| ) |
Registers a new command.
| command | Case-sensitive command name. |
| entry | Entry containing the handler, description, and argument list. |
| std::string Ship::Console::BuildUsage | ( | const CommandEntry & | entry | ) |
Builds a usage string directly from a CommandEntry.
| entry | CommandEntry to format. |
| std::string Ship::Console::BuildUsage | ( | const std::string & | command | ) |
Builds a usage string from the command's argument list.
| command | Registered command name. |
| CommandEntry & Ship::Console::GetCommand | ( | const std::string & | command | ) |
Returns a reference to the CommandEntry for the given command name.
| command | Registered command name. |
| std::map< std::string, CommandEntry > & Ship::Console::GetCommands | ( | ) |
Returns the full command registry (name → entry map).
Intended for auto-complete and help listing; prefer HasCommand() / Run() for dispatch.
| bool Ship::Console::HasCommand | ( | const std::string & | command | ) |
Returns true if a command with the given name is registered.
| command | Command name to look up (case-sensitive). |
|
overrideprotectedvirtual |
Registers built-in commands. Called automatically by Component::Init().
Required Context children: None.
Reimplemented from Ship::Component.
| int32_t Ship::Console::Run | ( | const std::string & | command, |
| std::string * | output | ||
| ) |
Registers built-in commands. Called by Component::Init().
Called automatically by Context::CreateDefaultInstance(); do not call manually. Use Component::Init() to trigger initialization.
Required Context children: None — Console has no external dependencies at initialization time.
Parses and dispatches a command string.
Tokenises command, looks up the first token in the command registry, and invokes the matching handler.
| command | Raw command string entered by the user (e.g. "set gCvar 1"). |
| output | If non-null, receives the handler's text response. |