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

MagicPrivate construction methods. More...

Collaboration diagram for Constructors:

Functions

 Recognition::Magic::MagicPrivate::MagicPrivate () noexcept=default
 Default constructor creates a closed instance.
 Recognition::Magic::MagicPrivate::MagicPrivate (FlagsMaskT flags_mask, const std::filesystem::path &database_file)
 Construct and initialize with flags (throwing version).
 Recognition::Magic::MagicPrivate::MagicPrivate (FlagsMaskT flags_mask, const std::nothrow_t &tag, const std::filesystem::path &database_file) noexcept
 Construct and initialize with flags (noexcept version).
 Recognition::Magic::MagicPrivate::MagicPrivate (const FlagsContainerT &flags_container, const std::filesystem::path &database_file)
 Construct with flags container (throwing version).
 Recognition::Magic::MagicPrivate::MagicPrivate (const FlagsContainerT &flags_container, const std::nothrow_t &tag, const std::filesystem::path &database_file) noexcept
 Construct with flags container (noexcept version).

Detailed Description

MagicPrivate construction methods.

Constructors for creating MagicPrivate instances in various initial states (closed, opened, or valid).

Function Documentation

◆ MagicPrivate() [1/5]

Recognition::Magic::MagicPrivate::MagicPrivate ( )
defaultnoexcept

Default constructor creates a closed instance.

Creates a MagicPrivate in the Closed state with:

  • m_cookie = nullptr
  • m_flags_mask = 0
  • m_is_database_loaded = false
Lifecycle State
After construction: Closed
See also
Open() to transition to Opened state

◆ MagicPrivate() [2/5]

Recognition::Magic::MagicPrivate::MagicPrivate ( const FlagsContainerT & flags_container,
const std::filesystem::path & database_file )
inline

Construct with flags container (throwing version).

Alternative constructor accepting a container of individual Flags values instead of a bitmask.

Parameters
[in]flags_containerContainer (vector) of Flags enum values.
[in]database_filePath to magic database file to load.
Exceptions
MagicOpenErrorIf magic_open() fails.
EmptyPathIf database_file is empty.
PathDoesNotExistIf database_file does not exist.
PathIsNotRegularFileIf database_file is not a regular file.
MagicLoadDatabaseFileErrorIf magic_load() fails.
Lifecycle Transition
ClosedOpenedValid
Usage Example
MagicPrivate impl{flags, "/path/to/magic"};
PIMPL implementation class for Magic.
Definition magic.cpp:222
std::vector< Flags > FlagsContainerT
Container type holding a collection of Magic::Flags.
Definition magic.hpp:401
@ Mime
Definition magic.hpp:328
@ Compress
Definition magic.hpp:319
See also
Magic::Magic(const FlagsContainerT&, const std::filesystem::path&)

◆ MagicPrivate() [3/5]

Recognition::Magic::MagicPrivate::MagicPrivate ( const FlagsContainerT & flags_container,
const std::nothrow_t & tag,
const std::filesystem::path & database_file )
inlinenoexcept

Construct with flags container (noexcept version).

Non-throwing variant accepting a container of Flags values. Silently fails if initialization encounters errors.

Parameters
[in]flags_containerContainer (vector) of Flags enum values.
[in]tagPass std::nothrow to select this overload.
[in]database_filePath to magic database file to load.
Lifecycle State
After construction:
  • Valid if both Open() and LoadDatabaseFile() succeed
  • Opened if only Open() succeeds
  • Closed if Open() fails
Note
Check IsValid() after construction to verify success.
See also
Magic::Magic(const FlagsContainerT&, const std::nothrow_t&, const std::filesystem::path&)

◆ MagicPrivate() [4/5]

Recognition::Magic::MagicPrivate::MagicPrivate ( FlagsMaskT flags_mask,
const std::filesystem::path & database_file )
inline

Construct and initialize with flags (throwing version).

Creates a MagicPrivate, opens it with the specified flags, and loads the magic database file in a single step.

Parameters
[in]flags_maskConfiguration flags as a bitmask.
[in]database_filePath to magic database file to load.
Exceptions
MagicOpenErrorIf magic_open() fails.
EmptyPathIf database_file is empty.
PathDoesNotExistIf database_file does not exist.
PathIsNotRegularFileIf database_file is not a regular file.
MagicLoadDatabaseFileErrorIf magic_load() fails.
Lifecycle Transition
ClosedOpenedValid
Implementation
Open(flags_mask); // Closed -> Opened
LoadDatabaseFile(database_file); // Opened -> Valid
void LoadDatabaseFile(const std::filesystem::path &database_file)
Load a magic database file (throwing version).
Definition magic.cpp:1356
void Open(FlagsMaskT flags_mask)
Open the magic instance with flags (throwing version).
Definition magic.cpp:1468
See also
Magic::Magic(FlagsMaskT, const std::filesystem::path&)

◆ MagicPrivate() [5/5]

Recognition::Magic::MagicPrivate::MagicPrivate ( FlagsMaskT flags_mask,
const std::nothrow_t & tag,
const std::filesystem::path & database_file )
inlinenoexcept

Construct and initialize with flags (noexcept version).

Non-throwing variant that silently fails on errors. The short-circuit evaluation ensures LoadDatabaseFile() is only called if Open() succeeds.

Parameters
[in]flags_maskConfiguration flags as a bitmask.
[in]tagPass std::nothrow to select this overload.
[in]database_filePath to magic database file to load.
Lifecycle State
After construction:
  • Valid if both Open() and LoadDatabaseFile() succeed
  • Opened if only Open() succeeds
  • Closed if Open() fails
Implementation
Uses short-circuit && to ensure proper sequencing:
Open(flags_mask, std::nothrow) // Only proceed if true
&& LoadDatabaseFile(std::nothrow, database_file);
Note
Check IsValid() after construction to verify success.
See also
Magic::Magic(FlagsMaskT, const std::nothrow_t&, const std::filesystem::path&)