CONZEPT 16 C++ API
C16::BinaryObject Class Reference

Binary object buffer to operate on binary objects. More...

#include "C16/Binary.hpp"

Inheritance diagram for C16::BinaryObject:
C16::Binary

Detailed Description

Binary object buffer to operate on binary objects.

Public Types

enum  Compression {
  Compression::NONE, Compression::LOW, Compression::MEDIUM, Compression::HIGH,
  Compression::MAXIMUM
}
 Compression of a binary object. More...
 
- Public Types inherited from C16::Binary
enum  Error { Error::CONTENT_EMPTY = 1, Error::CIPHER_KEY_INCORRECT, Error::OPERATION_UNAVAILABLE }
 Error of an operation on a binary. More...
 

Static Public Attributes

static const int TYPE_LENGTH_LIMIT = 60
 Type length limit. More...
 
static const int USER_LENGTH_LIMIT = 20
 User length limit. More...
 
- Static Public Attributes inherited from C16::Binary
static const int NAME_LENGTH_LIMIT = 60
 Name length limit. More...
 
static const int CUSTOM_LENGTH_LIMIT = 255
 Custom property length limit. More...
 

Public Member Functions

 BinaryObject ()
 Constructs a binary object buffer. More...
 
long long int storage_id () const
 Gets the storage id of the loaded binary object. More...
 
const std::string & type () const
 Gets the type the loaded binary object. More...
 
void type_set (const std::string &type)
 Sets the type of the loaded binary object. More...
 
const std::string & type_custom () const
 Gets the custom type the loaded binary object. More...
 
void type_custom_set (const std::string &type_custom)
 Sets the custom type of the loaded binary object. More...
 
long long int size () const
 Gets the size of the loaded binary object in units of bytes. More...
 
long long int storage_consumption () const
 Gets the storage consumption of the loaded binary object in units of bytes. More...
 
Value::Moment created_moment () const
 Gets the moment of the creation of the loaded binary object. More...
 
void created_moment_set (const Value::Moment &moment)
 Sets the moment of the creation of the loaded binary object. More...
 
const std::string & created_user () const
 Gets the user who created the loaded binary object. More...
 
void created_user_set (const std::string &user)
 Sets the user who created the loaded binary object. More...
 
Value::Moment modified_moment () const
 Gets the moment of the last modification of the loaded binary object. More...
 
void modified_moment_set (const Value::Moment &moment)
 Sets the moment of the last modification of the loaded binary object. More...
 
const std::string & modified_user () const
 Gets the user who last modified the loaded binary object. More...
 
void modified_user_set (const std::string &user)
 Sets the user who last modified the loaded binary object. More...
 
Value::Moment modified_moment_file () const
 Gets the moment of the last file modification of the loaded binary object. More...
 
void modified_moment_file_set (const Value::Moment &moment)
 Sets the moment of the last file modification of the loaded binary object. More...
 
Compression compression () const
 Gets the compression of the loaded binary object. More...
 
Result read (const BinaryDirectory &directory, const std::string &name, Place place=Place::KEY, Locking locking=Locking::NONE) override
 Reads a binary by means of a base binary directory, a reference name and a place into the binary buffer. More...
 
Result read (const BinaryDirectory &directory, Place place, Locking locking=Locking::NONE) override
 Reads a binary by means of a base binary directory and a place into the binary buffer. More...
 
Result read (const BinaryDirectory &directory, const std::string &path, Locking locking=Locking::LOCK_SHARED) override
 Reads a binary by means of a base binary directory and a path into the binary buffer. More...
 
void unload () override
 Unloads the loaded binary. More...
 
Result write () const override
 Writes the loaded binary. More...
 
Result create (const BinaryDirectory &directory, const std::string &path, Locking locking=Locking::LOCK_SHARED, bool overwrite=false) override
 Creates and loads a binary. More...
 
Result content_copy_from (const BinaryObject &other)
 Copies the contents from another binary object to the loaded binary object. More...
 
Result content_export_to_file (const std::string &file_path, const std::string &cipher_key=std::string()) const
 Exports the content of the loaded binary object to a file. More...
 
Result content_import_from_file (const std::string &file_path, Compression compression=Compression::NONE, const std::string &cipher_key=std::string())
 Imports the content of the loaded binary object from a file. More...
 
- Public Member Functions inherited from C16::Binary
const Databasedatabase () const
 Gets the database of the loaded binary. More...
 
Databasedatabase ()
 Gets the database of the loaded binary. More...
 
bool loaded () const
 Gets if a binary is loaded into the binary buffer. More...
 
bool locked () const
 Gets if the loaded binary is locked by the user accessing the database. More...
 
long long int id () const
 Gets the id of the loaded binary. More...
 
const std::string & name () const
 Gets the name of the loaded binary. More...
 
const std::string & path () const
 Gets the path of the loaded binary. More...
 
const std::string & custom () const
 Gets the custom property of the loaded binary. More...
 
virtual void custom_set (const std::string &custom)
 Sets the custom property of the loaded binary. More...
 
virtual Result rename (const std::string &name)
 Renames the loaded binary. More...
 
virtual Result move_to (const BinaryDirectory &directory)
 Moves the loaded binary to another directory. More...
 

Member Enumeration Documentation

◆ Compression

Compression of a binary object.

Enumerator
NONE 

No compression.

LOW 

Low compression.

MEDIUM 

Medium compression.

HIGH 

High compression.

MAXIMUM 

Maximum compression.

Member Data Documentation

◆ TYPE_LENGTH_LIMIT

const int C16::BinaryObject::TYPE_LENGTH_LIMIT = 60
static

Type length limit.

◆ USER_LENGTH_LIMIT

const int C16::BinaryObject::USER_LENGTH_LIMIT = 20
static

User length limit.

Constructor & Destructor Documentation

◆ BinaryObject()

C16::BinaryObject::BinaryObject ( )

Constructs a binary object buffer.

Member Function Documentation

◆ storage_id()

long long int C16::BinaryObject::storage_id ( ) const

Gets the storage id of the loaded binary object.

◆ type()

const std::string& C16::BinaryObject::type ( ) const

Gets the type the loaded binary object.

◆ type_set()

void C16::BinaryObject::type_set ( const std::string &  type)

Sets the type of the loaded binary object.

Parameters
typeType (0 to TYPE_LENGTH_LIMIT characters)
Exceptions
Exception::InvalidityType invalid.
Note
The modification will be applied after writing the binary object.

◆ type_custom()

const std::string& C16::BinaryObject::type_custom ( ) const

Gets the custom type the loaded binary object.

◆ type_custom_set()

void C16::BinaryObject::type_custom_set ( const std::string &  type_custom)

Sets the custom type of the loaded binary object.

Parameters
type_customType (0 to TYPE_LENGTH_LIMIT characters)
Exceptions
Exception::InvalidityType invalid.
Note
The modification will be applied after writing the binary object.

◆ size()

long long int C16::BinaryObject::size ( ) const

Gets the size of the loaded binary object in units of bytes.

◆ storage_consumption()

long long int C16::BinaryObject::storage_consumption ( ) const

Gets the storage consumption of the loaded binary object in units of bytes.

◆ created_moment()

Value::Moment C16::BinaryObject::created_moment ( ) const

Gets the moment of the creation of the loaded binary object.

◆ created_moment_set()

void C16::BinaryObject::created_moment_set ( const Value::Moment moment)

Sets the moment of the creation of the loaded binary object.

Parameters
momentMoment
Note
The modification will be applied after writing the binary object.

◆ created_user()

const std::string& C16::BinaryObject::created_user ( ) const

Gets the user who created the loaded binary object.

◆ created_user_set()

void C16::BinaryObject::created_user_set ( const std::string &  user)

Sets the user who created the loaded binary object.

Parameters
userUser (0 to USER_LENGTH_LIMIT characters)
Exceptions
Exception::InvalidityUser invalid.
Note
The modification will be applied after writing the binary object.

◆ modified_moment()

Value::Moment C16::BinaryObject::modified_moment ( ) const

Gets the moment of the last modification of the loaded binary object.

◆ modified_moment_set()

void C16::BinaryObject::modified_moment_set ( const Value::Moment moment)

Sets the moment of the last modification of the loaded binary object.

Parameters
momentMoment
Note
The modification will be applied after writing the binary object.

◆ modified_user()

const std::string& C16::BinaryObject::modified_user ( ) const

Gets the user who last modified the loaded binary object.

◆ modified_user_set()

void C16::BinaryObject::modified_user_set ( const std::string &  user)

Sets the user who last modified the loaded binary object.

Parameters
userUser (0 to USER_LENGTH_LIMIT characters)
Exceptions
Exception::InvalidityUser invalid.
Note
The modification will be applied after writing the binary object.

◆ modified_moment_file()

Value::Moment C16::BinaryObject::modified_moment_file ( ) const

Gets the moment of the last file modification of the loaded binary object.

◆ modified_moment_file_set()

void C16::BinaryObject::modified_moment_file_set ( const Value::Moment moment)

Sets the moment of the last file modification of the loaded binary object.

Parameters
momentMoment
Note
The modification will be applied after writing the binary object.

◆ compression()

Compression C16::BinaryObject::compression ( ) const

Gets the compression of the loaded binary object.

◆ read() [1/3]

Result C16::BinaryObject::read ( const BinaryDirectory directory,
const std::string &  name,
Place  place = Place::KEY,
Locking  locking = Locking::NONE 
)
overridevirtual

Reads a binary by means of a base binary directory, a reference name and a place into the binary buffer.

Parameters
directoryBase binary directory buffer
nameReference name (case insensitive, 0 to NAME_LENGTH_LIMIT characters)
placePlace of the binary
Place::KEYReads the binary with the same name as the reference name.
Place::NEXTReads the binary with the name following the reference name.
Place::PREVIOUSReads the binary with the name preceding the reference name.
lockingLocking to apply to the binary
Locking::NONEDoes not lock the binary.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the binary.
Locking::LOCK_SINGLEApplies an exclusive, singulary lock to the binary.
Locking::LOCK_SHAREDApplies a shared lock to the binary.
Returns
Result
Return values
Result::OKBinary loaded and locking applied.
Result::LOCKEDBinary already locked. No binary loaded.
Result::NO_RECBinary inexistent or base binary directory buffer not loaded.
Result::NO_LOCKBase binary directory not locked.
Exceptions
Exception::InvalidityName invalid.
Exception::InvalidityPlace invalid.
Exception::InvalidityLocking invalid.
ExceptionOperation unavailable.
This is a root directory.
Note
Binaries are ordered by name (lexographicaly).

Implements C16::Binary.

◆ read() [2/3]

Result C16::BinaryObject::read ( const BinaryDirectory directory,
Place  place,
Locking  locking = Locking::NONE 
)
overridevirtual

Reads a binary by means of a base binary directory and a place into the binary buffer.

Parameters
directoryBase binary directory buffer
placePlace of the binary
Place::FIRSTReads the first binary.
Place::LASTReads the last binary.
Place::NEXTReads the binary with the name following the name of the loaded binary.
Place::PREVIOUSReads binary text with the name preceding the name of the loaded binary.
lockingLock to apply to the binary
Locking::NONEDoes not lock the binary.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the binary.
Locking::LOCK_SINGLEApplies an exclusive, singulary lock to the binary.
Locking::LOCK_SHAREDApplies a shared lock to the binary.
Returns
Result
Return values
Result::OKBinary loaded and locking applied.
Result::LOCKEDBinary already locked. No binary loaded.
Result::NO_RECBinary inexistent or base binary directory buffer not loaded.
Result::NO_LOCKBase binary directory not locked.
Exceptions
Exception::InvalidityPlace invalid.
Exception::InvalidityLocking invalid.
ExceptionOperation unavailable.
This is a root directory.
Note
Binaries are ordered by name (lexographicaly).

Implements C16::Binary.

◆ read() [3/3]

Result C16::BinaryObject::read ( const BinaryDirectory directory,
const std::string &  path,
Locking  locking = Locking::LOCK_SHARED 
)
overridevirtual

Reads a binary by means of a base binary directory and a path into the binary buffer.

Parameters
directoryBase binary directory buffer
pathPath to the binary relative to the base binary directory
lockingLocking to apply to the binary
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the binary.
Locking::LOCK_SINGLEApplies an exclusive, singulary lock to the binary.
Locking::LOCK_SHAREDApplies a shared lock to the binary.
Returns
Result
Return values
Result::OKBinary loaded and locking applied.
Result::NO_KEYBinary inexistent but following binary existent and loaded.
Result::LAST_RECBinary and following binary inexistent but preceding binary existent and loaded.
Result::NO_RECBinary inexistent or base binary directory buffer not loaded.
Result::NO_LOCKBase binary directory not locked.
Result::DEADLOCKDeadlock occurred.
Exceptions
Exception::InvalidityName invalid.
Exception::InvalidityLocking invalid.
ExceptionOperation unavailable.
This is a root directory.

Implements C16::Binary.

◆ unload()

void C16::BinaryObject::unload ( )
overridevirtual

Unloads the loaded binary.

Exceptions
ExceptionOperation unavailable.
This is a root directory.

Implements C16::Binary.

◆ write()

Result C16::BinaryObject::write ( ) const
overridevirtual

Writes the loaded binary.

Returns
Result
Return values
Result::OKBinary written.
Result::NO_RECNo binary loaded.
Result::NO_LOCKBinary not exclusively locked.
Result::DEADLOCKDeadlock occurred.
Exceptions
ExceptionOperation unavailable.
This is a root directory.

Implements C16::Binary.

◆ create()

Result C16::BinaryObject::create ( const BinaryDirectory directory,
const std::string &  path,
Locking  locking = Locking::LOCK_SHARED,
bool  overwrite = false 
)
overridevirtual

Creates and loads a binary.

Parameters
directoryBase binary directory buffer
pathPath to the binary relative to the base binary directory
lockingLocking to apply to the binary
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the binary.
Locking::LOCK_SINGLEApplies an exclusive, singulary lock to the binary.
Locking::LOCK_SHAREDApplies a shared lock to the binary.
overwriteOption to overwrite a binary with the same name (case insensitive)
Returns
Result
Return values
Result::OKBinary created, loaded and locking applied.
Result::NO_RECNo binary loaded.
Result::EXISTSBinary with same name (case insensitive) already existent.
Result::NO_LOCKBinary not exclusively locked or base binary directory not locked.
Result::DEADLOCKDeadlock occurred.
Exceptions
Exception::InvalidityName invalid.
ExceptionOperation unavailable.
Possible reasons:
  • This is a root directory.
  • This is an object and the destination directory is a root directory.
  • Nesting too deep.

Implements C16::Binary.

◆ content_copy_from()

Result C16::BinaryObject::content_copy_from ( const BinaryObject other)

Copies the contents from another binary object to the loaded binary object.

Parameters
otherAnother binary object
Returns
Result
Return values
Result::OKBinary object content copied.
Result::NO_RECNo binary object loaded.
Result::NO_LOCKBinary object not locked or other binary object not exclusively locked.
Result::DEADLOCKDeadlock occurred.
Exceptions
Exception::DifferenceDatabase different.
Database of this binary is different to database of the other object.

◆ content_export_to_file()

Result C16::BinaryObject::content_export_to_file ( const std::string &  file_path,
const std::string &  cipher_key = std::string() 
) const

Exports the content of the loaded binary object to a file.

Parameters
file_pathPath to the file
cipher_keyCipher key to decrypt the binary object
Returns
Result
Return values
Result::OKBinary object content exported to file.
Result::NO_RECNo binary object loaded.
Exceptions
ExceptionContent empty.
ExceptionCipher key incorrect.
Filesystem::ExceptionFilesystem exception occured.
Note
Sets the time of the last modification of the file to the moment of the last file modification.

◆ content_import_from_file()

Result C16::BinaryObject::content_import_from_file ( const std::string &  file_path,
Compression  compression = Compression::NONE,
const std::string &  cipher_key = std::string() 
)

Imports the content of the loaded binary object from a file.

Parameters
file_pathPath to the file
compressionCompression
cipher_keyCipher key to encrypt the binary object
Returns
Result
Return values
Result::OKBinary object content imported from file.
Result::NO_RECNo binary object loaded.
Result::NO_LOCKBinary object not exclusively locked.
Result::DEADLOCKDeadlock occurred.
Exceptions
ExceptionContent empty.
Filesystem::ExceptionFilesystem exception occured.
Note
Sets the moment of the last file modification to the time of the last modification of the file.