libept
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ept::debtags::Vocabulary Class Reference

#include <vocabulary.h>

Public Member Functions

 Vocabulary (bool empty=false)
 Instantiate the Debtags vocabulary. More...
 
 ~Vocabulary ()
 
time_t timestamp () const
 Get the timestamp of when the index was last updated. More...
 
bool hasData () const
 Return true if this data source has data, false if it's empty. More...
 
bool empty () const
 Check if there is any data in the merged vocabulary. More...
 
bool hasFacet (const std::string &name) const
 Check if the vocabulary contains the facet `name'. More...
 
bool hasTag (const std::string &name) const
 Check if the vocabulary contains the tag `fullname'. More...
 
const voc::FacetDatafacetData (const std::string &name) const
 Return the facet with the given name. More...
 
const voc::TagDatatagData (const std::string &fullname) const
 Return the tag with the given full name. More...
 
std::set< std::string > facets () const
 Return all the facets in the vocabulary. More...
 
std::set< std::string > tags () const
 Return all the tags in the vocabulary. More...
 
std::set< std::string > tags (const std::string &facet) const
 Return the tags in the given facet. More...
 
void load (const std::string &pathname)
 Load vocabulary data from the given file. More...
 
void read (FILE *input, const std::string &pathname)
 Parse and import the vocabulary from `input', merging the data with the previously imported ones. More...
 
void write ()
 Atomically update the system vocabulary. More...
 
void write (const std::string &fname)
 Atomically write the vocabulary data to the given file. More...
 

Static Public Member Functions

static std::string pathname ()
 Return the default pathname for the vocabulary. More...
 

Protected Member Functions

void parseVocBuf (std::map< std::string, std::string > &res, size_t ofs, size_t len) const
 
voc::FacetDataobtainFacet (const std::string &name)
 
voc::TagDataobtainTag (const std::string &fullname)
 
void write (std::ostream &out)
 Write the vocabulary data to the given output stream. More...
 

Protected Attributes

std::map< std::string, voc::FacetDatam_facets
 
time_t m_timestamp
 
std::map< std::string, std::string > emptyData
 

Constructor & Destructor Documentation

◆ Vocabulary()

ept::debtags::Vocabulary::Vocabulary ( bool  empty = false)

Instantiate the Debtags vocabulary.

Parameters
emptyfalse if the Debtags vocabulary should be loaded, true if it should start as an empty vocabulary

References load(), and pathname().

◆ ~Vocabulary()

ept::debtags::Vocabulary::~Vocabulary ( )

Member Function Documentation

◆ empty()

bool ept::debtags::Vocabulary::empty ( ) const
inline

Check if there is any data in the merged vocabulary.

References ept::debtags::voc::Data::name.

◆ facetData()

const voc::FacetData * ept::debtags::Vocabulary::facetData ( const std::string &  name) const

Return the facet with the given name.

References m_facets.

Referenced by hasTag(), tagData(), and tags().

◆ facets()

std::set< std::string > ept::debtags::Vocabulary::facets ( ) const

Return all the facets in the vocabulary.

References m_facets, and res.

◆ hasData()

bool ept::debtags::Vocabulary::hasData ( ) const
inline

Return true if this data source has data, false if it's empty.

◆ hasFacet()

bool ept::debtags::Vocabulary::hasFacet ( const std::string &  name) const

Check if the vocabulary contains the facet `name'.

References m_facets.

◆ hasTag()

bool ept::debtags::Vocabulary::hasTag ( const std::string &  name) const

Check if the vocabulary contains the tag `fullname'.

References facetData(), ept::debtags::voc::getfacet(), and ept::debtags::voc::FacetData::hasTag().

◆ load()

void ept::debtags::Vocabulary::load ( const std::string &  pathname)

Load vocabulary data from the given file.

References ept::sys::exists(), m_timestamp, read(), and ept::sys::timestamp().

Referenced by Vocabulary().

◆ obtainFacet()

voc::FacetData & ept::debtags::Vocabulary::obtainFacet ( const std::string &  name)
protected

References m_facets, and res.

Referenced by obtainTag(), and read().

◆ obtainTag()

voc::TagData & ept::debtags::Vocabulary::obtainTag ( const std::string &  fullname)
protected

◆ parseVocBuf()

void ept::debtags::Vocabulary::parseVocBuf ( std::map< std::string, std::string > &  res,
size_t  ofs,
size_t  len 
) const
protected

◆ pathname()

string ept::debtags::Vocabulary::pathname ( )
static

Return the default pathname for the vocabulary.

This returns /var/lib/debtags/vocabulary, unless it has been overridden by setting $DEBTAGS_VOCABULARY

References res.

Referenced by Vocabulary(), and write().

◆ read()

void ept::debtags::Vocabulary::read ( FILE *  input,
const std::string &  pathname 
)

Parse and import the vocabulary from `input', merging the data with the previously imported ones.

References ept::debtags::DebDBParser::fileName(), ept::debtags::voc::Data::name, ept::debtags::DebDBParser::nextRecord(), obtainFacet(), and obtainTag().

Referenced by load().

◆ tagData()

const voc::TagData * ept::debtags::Vocabulary::tagData ( const std::string &  fullname) const

Return the tag with the given full name.

References facetData(), ept::debtags::voc::getfacet(), and ept::debtags::voc::FacetData::tagData().

◆ tags() [1/2]

std::set< std::string > ept::debtags::Vocabulary::tags ( ) const

Return all the tags in the vocabulary.

References m_facets, and res.

◆ tags() [2/2]

std::set< std::string > ept::debtags::Vocabulary::tags ( const std::string &  facet) const

Return the tags in the given facet.

References facetData(), and ept::debtags::voc::FacetData::tags().

◆ timestamp()

time_t ept::debtags::Vocabulary::timestamp ( ) const
inline

Get the timestamp of when the index was last updated.

◆ write() [1/3]

void ept::debtags::Vocabulary::write ( std::ostream &  out)
protected

Write the vocabulary data to the given output stream.

References m_facets.

◆ write() [2/3]

void ept::debtags::Vocabulary::write ( )

Atomically update the system vocabulary.

References pathname().

Referenced by write().

◆ write() [3/3]

void ept::debtags::Vocabulary::write ( const std::string &  fname)

Atomically write the vocabulary data to the given file.

References write(), and ept::sys::write_file_atomically().

Member Data Documentation

◆ emptyData

std::map<std::string, std::string> ept::debtags::Vocabulary::emptyData
protected

◆ m_facets

std::map<std::string, voc::FacetData> ept::debtags::Vocabulary::m_facets
protected

◆ m_timestamp

time_t ept::debtags::Vocabulary::m_timestamp
protected

Referenced by load().


The documentation for this class was generated from the following files: