Libmagicxx v10.0.3
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
Loading...
Searching...
No Matches
Instance Control

Instance lifecycle management. More...

Collaboration diagram for Instance Control:

Functions

void Recognition::Magic::Close () noexcept
 Close the Magic instance.
static bool Recognition::Magic::Compile (const std::filesystem::path &database_file=DEFAULT_DATABASE_FILE) noexcept
 Compile a magic database file.

Detailed Description

Instance lifecycle management.

Methods for closing instances and compiling databases.

Function Documentation

◆ Close()

void Recognition::Magic::Close ( )
noexcept

Close the Magic instance.

Releases all libmagic resources and transitions the instance to the Closed state. After calling Close(), the instance is no longer valid for file identification until Open() and LoadDatabaseFile() are called again.

Lifecycle Transition
  • From OpenedClosed
  • From ValidClosed
  • From ClosedClosed (no-op)
Note
Safe to call multiple times (idempotent). Automatically called by the destructor.
See also
Magic Core "Magic Lifecycle" for state diagram
Open()
IsOpen()
Since
10.0.0
Examples
magic_examples.cpp.

◆ Compile()

bool Recognition::Magic::Compile ( const std::filesystem::path & database_file = DEFAULT_DATABASE_FILE)
staticnodiscardnoexcept

Compile a magic database file.

Static utility method that compiles magic source files into binary format. The compiled file is named with ".mgc" appended to the source filename.

Parameters
[in]database_filePath to database file to compile (default: DEFAULT_DATABASE_FILE).
Returns
true on successful compilation, false otherwise.
if (Magic::Compile("/path/to/magic")) {
// Creates /path/to/magic.mgc
std::println("Database compiled successfully");
}
static bool Compile(const std::filesystem::path &database_file=DEFAULT_DATABASE_FILE) noexcept
Compile a magic database file.
Definition magic.cpp:2481
Note
This is a static method - no Magic instance is required.
See also
Check()
Since
10.0.0
Examples
magic_examples.cpp.