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

Instance state inspection methods. More...

Collaboration diagram for State Queries:

Functions

bool Recognition::Magic::IsDatabaseLoaded () const noexcept
 Check if a magic database is loaded.
bool Recognition::Magic::IsOpen () const noexcept
 Check if the Magic instance is open.
bool Recognition::Magic::IsValid () const noexcept
 Check if the Magic instance is valid for file identification.

Detailed Description

Instance state inspection methods.

Methods for querying the current lifecycle state.

Function Documentation

◆ IsDatabaseLoaded()

bool Recognition::Magic::IsDatabaseLoaded ( ) const
nodiscardnoexcept

Check if a magic database is loaded.

Returns
true if a database is loaded (instance in Valid state), false otherwise (Closed or Opened state).
Lifecycle State Check
State Returns
Closed false
Opened false
Valid true
See also
Magic Core "Magic Lifecycle" for state diagram
LoadDatabaseFile()
IsOpen()
IsValid()
Since
10.0.0
Examples
magic_examples.cpp.

◆ IsOpen()

bool Recognition::Magic::IsOpen ( ) const
nodiscardnoexcept

Check if the Magic instance is open.

Returns
true if open (Opened or Valid state), false if Closed.
Lifecycle State Check
State Returns
Closed false
Opened true
Valid true
Note
An open instance may still not be valid for identification if no database is loaded. Use IsValid() to check both.
See also
Magic Core "Magic Lifecycle" for state diagram
Open()
Close()
IsValid()
Since
10.0.0
Examples
magic_examples.cpp.

◆ IsValid()

bool Recognition::Magic::IsValid ( ) const
nodiscardnoexcept

Check if the Magic instance is valid for file identification.

An instance is valid if it is both open and has a database loaded, i.e., it is in the Valid state.

Returns
true if in Valid state (open and database loaded), false if in Closed or Opened state.
Lifecycle State Check
State Returns
Closed false
Opened false
Valid true
Magic magic{Magic::Flags::Mime, std::nothrow};
if (magic.IsValid()) {
auto type = magic.IdentifyFile("file.txt");
}
Magic() noexcept
Default constructor. Creates an unopened Magic instance.
Definition magic.cpp:2421
FileTypeT IdentifyFile(const std::filesystem::path &path) const
Identify the type of a single file.
Definition magic.cpp:2530
@ Mime
Definition magic.hpp:328
bool IsValid() const noexcept
Check if the Magic instance is valid for file identification.
Definition magic.cpp:2633
See also
Magic Core "Magic Lifecycle" for state diagram
IsOpen()
IsDatabaseLoaded()
operator bool()
Since
10.0.0
Examples
magic_examples.cpp.