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

Text buffer to operate on texts of a database. More...

#include "C16/Text.hpp"

Inheritance diagram for C16::Text:
C16::Procedure

Detailed Description

Text buffer to operate on texts of a database.

Examples

Iteration

#include "C16/Library.hpp"
using namespace C16;
void texts_iterate(Database& database)
{
Text text(database);
for
(
Result result = text.read(Place::FIRST);
result != Result::NO_KEY;
result = text.read(Place::NEXT)
)
{
// Permissions insufficient
if (result == Result::NO_RIGHTS)
continue;
...
}
}

Classes

class  Stream
 Generic stream for text buffers. More...
 
class  StreamBuffer
 Generic stream buffer for text buffers. More...
 
class  StreamBufferInput
 Input stream buffer for reading text buffers. More...
 
class  StreamBufferOutput
 Output stream buffer for writing texts. More...
 
class  StreamInput
 Input stream for reading texts. More...
 
class  StreamOutput
 Output stream for writing texts. More...
 

Public Types

enum  LineBreak { LineBreak::NUL, LineBreak::CR, LineBreak::LF, LineBreak::CR_LF }
 Line break. More...
 

Static Public Attributes

static const int NAME_LENGTH_LIMIT = 20
 Name length limit. More...
 
static const int GROUP_LENGTH_LIMIT = 20
 Group length limit. More...
 

Public Member Functions

 Text (Database &database)
 Constructs a text buffer. More...
 
Databasedatabase () const
 Gets the database of the text buffer. More...
 
bool loaded () const
 Gets if a text is loaded into the text buffer. More...
 
const std::string & name () const
 Gets the name of the loaded text. More...
 
long int size () const
 Gets the size of the loaded text in units of bytes. More...
 
long int line_count () const
 Gets the line count of the loaded text. More...
 
const Value::Datecreated_date () const
 Gets the date of the creation of the loaded text. More...
 
const Value::Timecreated_time () const
 Gets the time of the creation of the loaded text. More...
 
const std::string & created_user () const
 Gets the user who created the loaded text. More...
 
const Value::Datemodified_date () const
 Gets the date of the last modification of the loaded text. More...
 
const Value::Timemodified_time () const
 Gets the time of the last modification of the loaded text. More...
 
const std::string & modified_user () const
 Gets the user who last modified the loaded text. More...
 
const std::string & group () const
 Gets the group of the loaded text. More...
 
void group_set (const std::string &group)
 Sets the group of the loaded text. More...
 
int right_read () const
 Gets the right required by a user to read the loaded text. More...
 
void right_read_set (int right_read)
 Sets the right required by a user to read the loaded text. More...
 
int right_write () const
 Gets the right required by a user to write the loaded text. More...
 
void right_write_set (int right_write)
 Sets the right required by a user to write the loaded text. More...
 
bool personal () const
 Gets if the loaded text is private. More...
 
void personal_set (bool personal)
 Sets if the loaded text is private. More...
 
const std::string & personal_user () const
 Gets the user who set the loaded text to private. More...
 
bool encrypted () const
 Gets if the loaded text is encrypted. More...
 
void encrypted_set (bool encrypted)
 Sets if the loaded text is encrypted. More...
 
std::string content (LineBreak line_break=LineBreak::LF) const
 Gets the content of the loaded text. More...
 
Result content_set (const std::string &content, LineBreak line_break=LineBreak::LF)
 Sets the content of the loaded text. More...
 
Result read (const std::string &name, Place place=Place::KEY, Locking locking=Locking::NONE)
 Reads a text by means of a reference name and a place into the text buffer. More...
 
Result read (Place place, Locking locking=Locking::NONE)
 Reads a text by means of a place into the text buffer. More...
 
Result reload (Locking locking=Locking::NONE)
 Reloads the loaded text. More...
 
void unload ()
 Unloads the loaded text. More...
 
Result write (Locking locking=Locking::NONE)
 Writes the loaded text. More...
 
Result create (const std::string &name, Locking locking=Locking::NONE)
 Creates and loads a text. More...
 
Result erase () const
 Deletes the loaded text. More...
 
Result rename (const std::string &name)
 Renames the loaded text. More...
 
Result copy (const std::string &name) const
 Copies the loaded text. More...
 

Member Enumeration Documentation

◆ LineBreak

enum C16::Text::LineBreak
strong

Line break.

Enumerator
NUL 

Null character (ASCII: 0, 0x0)

CR 

Carriage return (ASCII: 13, 0xD)

LF 

Line feed (ASCII: 10, 0xA)

CR_LF 

Carriage return & line feed (ASCII: 13 10, 0xD 0xA)

Member Data Documentation

◆ NAME_LENGTH_LIMIT

const int C16::Text::NAME_LENGTH_LIMIT = 20
static

Name length limit.

◆ GROUP_LENGTH_LIMIT

const int C16::Text::GROUP_LENGTH_LIMIT = 20
static

Group length limit.

Constructor & Destructor Documentation

◆ Text()

C16::Text::Text ( Database database)
explicit

Constructs a text buffer.

Parameters
databaseDatabase the text buffer relates to

Member Function Documentation

◆ database()

Database& C16::Text::database ( ) const

Gets the database of the text buffer.

◆ loaded()

bool C16::Text::loaded ( ) const

Gets if a text is loaded into the text buffer.

◆ name()

const std::string& C16::Text::name ( ) const

Gets the name of the loaded text.

◆ size()

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

Gets the size of the loaded text in units of bytes.

Note
Equals <character count> + 2 * <line count>

◆ line_count()

long int C16::Text::line_count ( ) const

Gets the line count of the loaded text.

◆ created_date()

const Value::Date& C16::Text::created_date ( ) const

Gets the date of the creation of the loaded text.

◆ created_time()

const Value::Time& C16::Text::created_time ( ) const

Gets the time of the creation of the loaded text.

◆ created_user()

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

Gets the user who created the loaded text.

◆ modified_date()

const Value::Date& C16::Text::modified_date ( ) const

Gets the date of the last modification of the loaded text.

◆ modified_time()

const Value::Time& C16::Text::modified_time ( ) const

Gets the time of the last modification of the loaded text.

◆ modified_user()

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

Gets the user who last modified the loaded text.

◆ group()

const std::string& C16::Text::group ( ) const

Gets the group of the loaded text.

◆ group_set()

void C16::Text::group_set ( const std::string &  group)

Sets the group of the loaded text.

Parameters
groupGroup of text (0 to GROUP_LENGTH_LIMIT characters)
Exceptions
Exception::InvalidityGroup invalid.
Note
The modification will be applied after writing the text.

◆ right_read()

int C16::Text::right_read ( ) const

Gets the right required by a user to read the loaded text.

◆ right_read_set()

void C16::Text::right_read_set ( int  right_read)

Sets the right required by a user to read the loaded text.

Parameters
right_readRight required by a user to read the text
Note
The modification will be applied after writing the text.

◆ right_write()

int C16::Text::right_write ( ) const

Gets the right required by a user to write the loaded text.

◆ right_write_set()

void C16::Text::right_write_set ( int  right_write)

Sets the right required by a user to write the loaded text.

Note
The modification will be applied after writing the text.

◆ personal()

bool C16::Text::personal ( ) const

Gets if the loaded text is private.

◆ personal_set()

void C16::Text::personal_set ( bool  personal)

Sets if the loaded text is private.

Parameters
personalIf the text is private
Note
The modification will be applied after writing the text.

◆ personal_user()

const std::string& C16::Text::personal_user ( ) const

Gets the user who set the loaded text to private.

◆ encrypted()

bool C16::Text::encrypted ( ) const

Gets if the loaded text is encrypted.

◆ encrypted_set()

void C16::Text::encrypted_set ( bool  encrypted)

Sets if the loaded text is encrypted.

Parameters
encryptedIf the text is encrypted
Note
The modification will be applied after writing the text.

◆ content()

std::string C16::Text::content ( LineBreak  line_break = LineBreak::LF) const

Gets the content of the loaded text.

Parameters
line_breakLine breaks within the content
See also
StreamInput

◆ content_set()

Result C16::Text::content_set ( const std::string &  content,
LineBreak  line_break = LineBreak::LF 
)

Sets the content of the loaded text.

Parameters
contentContent
line_breakLine breaks within the content
Returns
Result
Return values
Result::OKContent set.
Result::NO_RECNo text loaded.
Result::NO_LOCKText not exclusively locked.
Result::NO_RIGHTSPermissions insufficient.
Exceptions
Exception::InvalidityLine break invalid.
See also
StreamOutput

◆ read() [1/2]

Result C16::Text::read ( const std::string &  name,
Place  place = Place::KEY,
Locking  locking = Locking::NONE 
)

Reads a text by means of a reference name and a place into the text buffer.

Parameters
nameReference name (case insensitive, 0 to NAME_LENGTH_LIMIT characters)
placePlace of the text
Place::KEYReads the text with the same name as the reference name.
Place::NEXTReads the text with the name following the reference name.
Place::PREVIOUSReads the text with the name preceding the reference name.
lockingLocking to apply to the text
Locking::NONEDoes not change the lock of the text.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the text.
Locking::UNLOCKRemoves a lock applied by the accessing user from the text.
Returns
Result
Return values
Result::OKText loaded and locking applied.
Result::LOCKEDText loaded but already locked.
Result::NO_KEYText inexistent. Text with the name following the reference name loaded, if existent.
Result::NO_RIGHTSPermissions insufficient. Name of text loaded.
Exceptions
Exception::InvalidityName invalid.
Exception::InvalidityPlace invalid.
Exception::InvalidityLocking invalid.
Note
Texts are ordered by name (lexicographicaly).

◆ read() [2/2]

Result C16::Text::read ( Place  place,
Locking  locking = Locking::NONE 
)

Reads a text by means of a place into the text buffer.

Parameters
placePlace of the text
Place::FIRSTReads the first text.
Place::LASTReads the last text.
Place::NEXTReads the text with the name following the name of the loaded text.
Place::PREVIOUSReads the text with the name preceding the name of the loaded text.
lockingLocking to apply to the text
Locking::NONEDoes not change the lock of the text.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the text.
Locking::UNLOCKRemoves a lock applied by the accessing user from the text.
Returns
Result
Return values
Result::OKText loaded and locking applied.
Result::LOCKEDText loaded but already locked.
Result::NO_KEYText inexistent.
Result::NO_RECNo text loaded.
Result::NO_RIGHTSPermissions insufficient. Name of text loaded.
Exceptions
Exception::InvalidityPlace invalid.
Exception::InvalidityLocking invalid.
Note
Texts are ordered by name (lexicographicaly).
See also
Example

◆ reload()

Result C16::Text::reload ( Locking  locking = Locking::NONE)

Reloads the loaded text.

The text is identified by its name.

Parameters
lockingLocking to apply to the text
Locking::NONEDoes not change the lock of the text.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the text.
Locking::UNLOCKRemoves a lock applied by the accessing user from the text.
Returns
Result
Return values
Result::OKText loaded and locking applied.
Result::LOCKEDText loaded but already locked.
Result::NO_KEYText inexistent but following text loaded, if existent.
Result::NO_RECNo text loaded.
Result::NO_RIGHTSPermissions insufficient. Name of text loaded.
Note
Texts are ordered by name (lexicographicaly).

◆ unload()

void C16::Text::unload ( )

Unloads the loaded text.

◆ write()

Result C16::Text::write ( Locking  locking = Locking::NONE)

Writes the loaded text.

Parameters
lockingLocking to apply to the text
Locking::NONEDoes not change the lock of the text.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the text.
Locking::UNLOCKRemoves a lock applied by the accessing user from the text.
Returns
Result
Return values
Result::OKText written and locking applied.
Result::NO_RECNo text loaded.
Result::NO_LOCKText not exclusively locked.
Result::NO_RIGHTSPermissions insufficient.
Result::DEADLOCKDeadlock occurred.

◆ create()

Result C16::Text::create ( const std::string &  name,
Locking  locking = Locking::NONE 
)

Creates and loads a text.

Parameters
nameName of the text (1 to NAME_LENGTH_LIMIT characters)
lockingLocking to apply to the text
Locking::NONEDoes not lock the text.
Locking::LOCK_EXCLUSIVEApplies an exclusive lock to the text.
Returns
Result
Return values
Result::OKText created, loaded and locking applied.
Result::EXISTSText with same name (case insensitive) already existent. No text loaded.
Result::DEADLOCKDeadlock occurred. No text loaded.
Exceptions
Exception::InvalidityName invalid.
No text loaded.
Exception::InvalidityLocking invalid.
No text loaded.
See also
Texts::create

◆ erase()

Result C16::Text::erase ( ) const

Deletes the loaded text.

Returns
Result
Return values
Result::OKText deleted.
Result::LOCKEDText locked.
Result::NO_KEYText inexistent.
Result::NO_RECNo text loaded.
Result::NO_RIGHTSPermissions insufficient.
Result::DEADLOCKDeadlock occurred.
See also
Texts::erase

◆ rename()

Result C16::Text::rename ( const std::string &  name)

Renames the loaded text.

Parameters
nameName of the text after renaming it (1 to NAME_LENGTH_LIMIT characters)
Returns
Result
Return values
Result::OKText renamed.
Result::LOCKEDText locked.
Result::NO_KEYText inexistent.
Result::NO_RECNo text loaded.
Result::EXISTSText with same name (case insensitive) already existent.
Result::NO_RIGHTSPermissions insufficient.
Exceptions
Exception::InvalidityName invalid.
See also
Texts::rename

◆ copy()

Result C16::Text::copy ( const std::string &  name) const

Copies the loaded text.

Parameters
nameName of the copy of the text (1 to NAME_LENGTH_LIMIT characters)
Returns
Result
Return values
Result::OKText copied.
Result::LOCKEDText locked.
Result::NO_KEYText inexistent.
Result::NO_RECNo text loaded.
Result::EXISTSText with same name (case insensitive) already existent.
Result::NO_RIGHTSPermissions insufficient.
Result::DEADLOCKDeadlock occurred.
Exceptions
Exception::InvalidityName invalid.
See also
Texts::copy
C16::Result::NO_RIGHTS
@ NO_RIGHTS
Permissions insufficient.
C16::Place::NEXT
@ NEXT
Operate on the next entity.
C16::Place::FIRST
@ FIRST
Operate on the first entity.
C16::Text
Text buffer to operate on texts of a database.
Definition: Text.hpp:64
C16::Text::database
Database & database() const
Gets the database of the text buffer.
Library.hpp
CONZEPT 16 C++ API.
C16::Result::NO_KEY
@ NO_KEY
Entity inexistent but following entity existent.
C16::Database
Database hosted by a server.
Definition: Database.hpp:38
C16::Result
Result
Result of an operation related to a database entity.
Definition: Result.hpp:12
C16
Namespace.
Definition: Array.hpp:6