Stored Objects. More...

#include <gobjects.h>

Inheritance diagram for GObjects< C, hEvents >:
[legend]

Public Member Functions

 GObjects (GSession *session, size_t size, const R::RString &name, tObjType type)
 
virtual void InsertObj (C *obj, C *parent=0)
 
virtual void DeleteObj (C *obj)
 
size_t GetNbObjs (const C *obj) const
 
size_t GetMaxObjId (const C *obj) const
 
size_t GetMaxObjPos (const C *obj) const
 
R::RCursor< C > GetObjs (const C *obj) const
 
size_t GetObjs (C **&tab, bool alloc)
 
C * GetObj (const C *obj, size_t id, bool load=true, bool null=false)
 
C * GetObj (const C *obj, const R::RString &name, bool load=true, bool null=false)
 
void LoadIndex (const C *obj, GConcept *concept, R::RNumContainer< size_t, true > &refs)
 
void BuildIndex (const C *obj)
 
void LoadTree (const C *obj, GConceptTree *&tree, size_t blockid, size_t id)
 
void LoadTree (const C *obj, R::RContainer< GConceptRecord, false, true > &records, size_t &nbrecords, size_t &nbtoprecords, size_t &nbrefs)
 
bool FindDepthFirstRecord (const C *obj, GConceptRecord &rec, size_t idx)
 
bool FindRecord (const C *obj, GConceptRecord &rec, size_t synpos)
 
bool FindParentRecord (const C *obj, const GConceptRecord &search, GConceptRecord &rec)
 
bool FindFirstChildRecord (const C *obj, const GConceptRecord &search, GConceptRecord &rec, size_t idx)
 
bool FindNearestRecord (const C *obj, GConceptRecord &rec, size_t synpos)
 
bool FindNearestRecord (const C *obj, GConceptRecord &rec, size_t synpos, bool after)
 
bool FindRootRecord (const C *obj, const GConceptRecord &rec1, const GConceptRecord &rec2, GConceptRecord &rec)
 
size_t GetMinPosRecord (const C *obj, const GConceptRecord &rec, size_t nbbefore)
 
size_t GetMaxPosRecord (const C *obj, const GConceptRecord &rec, size_t nbafter)
 
size_t GetMaxPosRecord (const C *obj)
 
size_t GetMaxSyntacticPosRecord (const C *obj)
 
size_t GetNbTotalChildRecords (const C *obj, const GConceptRecord &rec)
 
virtual ~GObjects (void)
 

Private Member Functions

void Init (R::RConfig *config)
 
virtual void Clear (const C *obj, bool del)
 
void OpenFiles (R::RConfig *config, R::RString subdir)
 
bool DoCreateIndex (const C *obj) const
 
bool DoCreateTree (const C *obj) const
 
void AssignId (C *obj)
 
void LoadObjs (const C *obj)
 
void LoadDesc (const C *obj, R::RContainer< GVector, true, true > *&vectors, size_t blockid, size_t id)
 
void SaveDesc (const C *obj, const R::RContainer< GVector, true, true > &vectors, size_t &blockid, size_t id)
 
void FlushDesc (const C *obj)
 
void UpdateIndex (const C *obj, const GDescription &desc, size_t id, bool add)
 
void LoadNode (GConceptTree *tree, GConceptNode *parent)
 
void SaveNode (GConceptRecord *rec)
 
void SaveTree (const C *obj, const R::RContainer< GConceptRecord, false, true > &records, size_t nbrecords, size_t nbtoprecords, size_t nbrefs, size_t &blockid, size_t id)
 
void FlushTree (const C *obj)
 
void SeekRecord (const C *obj, size_t idx)
 
- Private Member Functions inherited from GKB
virtual ~GKB (void)=0
 
tObjState GetState (void) const
 
GStorageGetStorage (void) const
 
GConceptTypeGetTokenType (void) const
 
GConceptTypeGetDCMIType (void) const
 
GConceptTypeGetURIType (void) const
 
GConceptTypeGetNamedEntityType (void) const
 
GConceptTypeGetTaxonomyType (void) const
 
GConceptGetContent (void) const
 
GConceptGetUnknown (void) const
 
GConceptGetURI (void) const
 
GConceptGetNamedEntity (void) const
 
GConceptGetIsA (void) const
 
GConceptGetSynonym (void) const
 
GConceptGetPartOf (void) const
 
size_t GetNbObjs (const GConceptType *obj) const
 
size_t GetMaxObjId (const GConceptType *obj) const
 
GConceptTypeGetObj (const GConceptType *obj, char id, bool null)
 
GConceptTypeGetObj (const GConceptType *obj, const R::RString &name, bool null)
 
R::RCursor< GConceptTypeGetObjs (const GConceptType *obj) const
 
GConceptTypeInsertObj (const GConceptType *obj, tConceptCat cat, size_t id, const R::RString &name, const R::RString &desc, bool &newone)
 
GConceptTypeInsertObj (const GConceptType *obj, tConceptCat cat, size_t id, const R::RString &name, const R::RString &desc)
 
GConceptTypeInsertObj (const GConceptType *obj, tConceptCat cat, const R::RString &name, const R::RString &desc, bool &newone)
 
GConceptTypeInsertObj (const GConceptType *obj, tConceptCat cat, const R::RString &name, const R::RString &desc)
 
size_t GetNbObjs (const GConcept *obj) const
 
size_t GetMaxObjId (const GConcept *obj) const
 
R::RCursor< GConceptGetObjs (const GConcept *obj) const
 
GConceptGetObj (const GConcept *obj, size_t id)
 
GConceptGetObj (const GConcept *obj, GConceptType *type, const R::RString &concept, bool null=false)
 
GConceptInsertObj (const GConcept *obj, GConceptType *type, const R::RString &concept, bool &newone)
 
GConceptInsertObj (const GConcept *obj, GConceptType *type, const R::RString &concept)
 
GConceptInsertObj (const GConcept &concept, bool &newone)
 
GConceptInsertObj (const GConcept &concept)
 
GConceptRenameObj (GConcept *concept, const R::RString &name)
 
void DeleteObj (GConcept *concept)
 
GStatementGetObj (const GStatement *obj, size_t id, bool null=false)
 
GStatementGetObj (const GStatement *obj, GObject *subject, GObject *predicate, GObject *value, bool null=false)
 
GStatementInsertObj (const GStatement *obj, size_t id, GObject *subject, GObject *predicate, GObject *value, double weight, bool &newone)
 
GStatementInsertObj (const GStatement *obj, size_t id, GObject *subject, GObject *predicate, GObject *value, double weight)
 
 GKB (GSession *session)
 
void ClearIndex (tObjType type)
 
- Private Member Functions inherited from RObjectContainer< C, true >
 RObjectContainer (size_t first, size_t m, size_t i=0)
 
void VerifyTab (size_t max)
 
void Clear (size_t m=0, size_t i=0)
 
int Compare (const RObjectContainer< C, true > &) const
 
size_t GetNbObjs (void) const
 
size_t GetMaxObjId (void) const
 
size_t GetMaxObjPos (void) const
 
R::RCursor< C > GetObjs (size_t min=0, size_t max=SIZE_MAX) const
 
size_t GetObjs (C **&tab, bool alloc, size_t min=0, size_t max=0)
 
const C * operator[] (size_t id) const
 
C * operator[] (size_t id)
 
C * GetObj (const TUse &tag, bool sortkey=true)
 
bool InsertObj (C *obj)
 
void DeleteObj (C *obj)
 
void AssignId (C *obj)
 
virtual ~RObjectContainer (void)
 

Private Attributes

R::RString ObjName
 
tObjType Type
 
size_t MaxObjs
 
R::RKeyValueFile< R::RIntKey > * Desc
 
bool CreateIndex
 
R::RKeyValueFile< R::RIntKey > * Index
 
bool CreateTree
 
R::RKeyValueFile< R::RIntKey > * Tree
 
bool Loaded
 
R::RNumContainer< size_t, true > tmpRefs
 
R::RRWLock lObjects
 
R::RRWLock lDesc
 
R::RRWLock lIndex
 
R::RRWLock lTree
 
- Private Attributes inherited from GKB
GSessionSession
 
tObjState State
 
GStorageStorage
 
bool SaveResults
 
GConceptTypeTokenType
 
GConceptTypeDCMIType
 
GConceptTypeNamedEntityType
 
GConceptTypeURIType
 
GConceptTypeTaxonomyType
 
GConceptContent
 
GConceptNamedEntity
 
GConceptURI
 
GConceptIsA
 
GConceptSynonym
 
GConceptPartOf
 
GConceptUnknown
 
R::RObjectContainer
< GConceptType, true > 
ConceptTypes
 
R::RObjectHashContainer
< GConcept, true > 
Concepts
 
R::RContainer< GStatement,
true, false > 
StatementsByIds
 
- Private Attributes inherited from RObjectContainer< C, true >
RContainer< C, true, false > Objects
 
R::RContainer< ObjectRef, true,
true > 
ObjectsByRef
 
size_t FirstId
 

Detailed Description

template<class C, const R::hNotification * hEvents>
class GALILEI::GObjects< C, hEvents >

Stored Objects.

This class represents a set of objects (class C). It aims is to encapsulate all the storage aspects of the management.

Template Parameters
CThe class of the objects managed.
hEventsArray of notification to post concerning an object.

To manage correctly the objects, the list uses two static member functions of the class representing the elements (class C):

static inline bool C::HasDesc(void);
static inline bool C::HasTree(void);

The first one specifies if the corresponding objects have descriptions (such as documents) or not (such as users). The second one specifies if the objects have a structure (documents) or not (all the other objects a priori).

The first parameter of several methods is a pseudo-parameter. It is used to differentiate methods with identical names. Several null pointer constants called pDoc, pProfile,etc. are defined and can be used for this parameter. In practice, these methods are called as followed:

size_t NbDocs(List.GetNbObjs(pDoc);
size_t MaxProfileId(List.GetMaxObjId(pProfile);
R::RCursor<GDoc> Docs(List.GetObjs(pDoc);
GCommunity* Community(List.GetObj(pCommunity,4,true,true));

The reason for this trick is that C++ does not managed methods with the same name, the same parameters but different return types.

For the storage of trees (to store the full description if documents), each node is stored as a record (GConceptRecord). The nodes are stored with using a depth-first approach: the first root node is stored, followed by its first child node, followed by its first grandchild nodes, etc.

Constructor & Destructor Documentation

GObjects ( GSession session,
size_t  size,
const R::RString name,
tObjType  type 
)

Constructor of a set of stored objects.

Parameters
sessionSession.
sizeInitial size of the list.
nameName of the objects.
typeType of the objects.
virtual ~GObjects ( void  )
virtual

Destructor.

Member Function Documentation

virtual void InsertObj ( C *  obj,
C *  parent = 0 
)
virtual

Insert an object.

Parameters
objobject to insert.
selectedSpecify if the object is selected or not.
parentParent object. This parameter is only used by GClasses.

Reimplemented in GClasses.

virtual void DeleteObj ( C *  obj)
virtual

Delete an object.

Parameters
objobject to delete.

Reimplemented in GClasses.

size_t GetNbObjs ( const C *  obj) const

Get the number of objects.

Parameters
objPseudo-parameter.
size_t GetMaxObjId ( const C *  obj) const

Get the highest identifier of the objects.

Parameters
objPseudo-parameter.
size_t GetMaxObjPos ( const C *  obj) const

Get the highest position occupied by an object.

Parameters
objPseudo-parameter.
R::RCursor<C> GetObjs ( const C *  obj) const

Get the objects.

Parameters
objPseudo-parameter.
Returns
a cursor over the objects.
size_t GetObjs ( C **&  tab,
bool  alloc 
)

Fill an array of objects.

Parameters
tabArray that will be filled.
allocMust the array be allocated ?
Returns
number of objects in the array (including null pointers).
C* GetObj ( const C *  obj,
size_t  id,
bool  load = true,
bool  null = false 
)

Get an object based on its identifier.

Parameters
objPseudo-parameter.
idIdentifier of the object.
loadIf set to true, the object is eventually loaded into memory.
nullIf set to true, if the object does not exist, return 0, else an exception is generated.
Returns
a pointer to a object.
C* GetObj ( const C *  obj,
const R::RString name,
bool  load = true,
bool  null = false 
)

Get an object based on its name.

Parameters
objPseudo-parameter.
nameName of the object.
loadIf set to true, the object is eventually loaded into memory.
nullIf set to true, if the object does not exist, return 0, else an exception is generated.
Returns
a pointer to a object.
void LoadIndex ( const C *  obj,
GConcept concept,
R::RNumContainer< size_t, true > &  refs 
)

Load the identifiers of all objects described by a specific concept.

Parameters
objPseudo-parameter.
conceptConcept to search for.
refsIdentifiers of the objects.
void BuildIndex ( const C *  obj)

Build the index of all the objects from scratch. Since only the object descriptions are used, no occurrence information is available.

Parameters
objPseudo-parameter.
void LoadTree ( const C *  obj,
GConceptTree *&  tree,
size_t  blockid,
size_t  id 
)

Load the concept tree of a given object. This method generates an exception for all objects excepted documents.

Parameters
objPseudo-parameter.
treeConcept tree. If null,it is created.
blockidIdentifier of the block of the document.
idIdentifier of the document.
void LoadTree ( const C *  obj,
R::RContainer< GConceptRecord, false, true > &  records,
size_t &  nbrecords,
size_t &  nbtoprecords,
size_t &  nbrefs 
)

Load the tree as a container of records.

Parameters
objObj for which the tree must be loaded.
recordsContainer of records (modified by the method).
nbrecordsNumber of records used for the document tree (modified by the method).
nbtoprecordsNumber of top records (modified by the method).
nbrefsNumber of concepts referenced (modified by the method).
void Init ( R::RConfig config)
private

Initialize the parameters.

Parameters
configConfiguration structure.
virtual void Clear ( const C *  obj,
bool  del 
)
privatevirtual

Clear the list.

Parameters
objPseudo-parameter.
listSpecify if the objects must be deleted or just their descriptions.

Reimplemented in GClasses.

void OpenFiles ( R::RConfig config,
R::RString  subdir 
)
private

Open the files in a given directory.

Parameters
configConfiguration structure.
subdirSub-directory where the files will be stored.
bool DoCreateIndex ( const C *  obj) const
private
Returns
if an index is create.
Parameters
objPseudo-parameter.
bool DoCreateTree ( const C *  obj) const
private
Returns
if the concept trees are created.
Parameters
objPseudo-parameter.
void AssignId ( C *  obj)
private

Assign an identifier to an object.

Parameters
objObject.
void LoadObjs ( const C *  obj)
private

Load all the objects.

Parameters
objPseudo-parameter.
void LoadDesc ( const C *  obj,
R::RContainer< GVector, true, true > *&  vectors,
size_t  blockid,
size_t  id 
)
private

Load the description of a given object.

Parameters
objPseudo-parameter.
vectorsVectors.
blockidIdentifier of the block of the object.
idIdentifier of the object.
void SaveDesc ( const C *  obj,
const R::RContainer< GVector, true, true > &  vectors,
size_t &  blockid,
size_t  id 
)
private

Save the description of a given object.

Parameters
objPseudo-parameter.
vectorsVectors.
blockidIdentifier of the block of the object (0 means the block will be found).
idIdentifier of the object.
void FlushDesc ( const C *  obj)
private

Flush the descriptions of the objects.

Parameters
objPseudo-parameter.
void UpdateIndex ( const C *  obj,
const GDescription desc,
size_t  id,
bool  add 
)
private

Update the index of a given object that is only described by a description.

Parameters
objPseudo-parameter.
descDescription.
idIdentifier of the object.
addObject must be added or removed from the index.
void LoadNode ( GConceptTree tree,
GConceptNode parent 
)
private

Load the next node in the file into a given tree. The method loads first the node information and then the method is called for its children.

Parameters
treeTree that will contain the new node.
parentParent node of the one to load.
void SaveNode ( GConceptRecord rec)
private

Save a record in the file. The method saves first the node information and then calls the method for its children.

Parameters
nodeNode to save.
void SaveTree ( const C *  obj,
const R::RContainer< GConceptRecord, false, true > &  records,
size_t  nbrecords,
size_t  nbtoprecords,
size_t  nbrefs,
size_t &  blockid,
size_t  id 
)
private

Save the concept tree of a given object. This method generates an exception except for documents.

Parameters
objPseudo-parameter.
recordsContainer of records.
nbrecordsNumber of records used for the document tree.
nbtoprecordsNumber of top records.
nbrefsNumber of concepts referenced.
blockidIdentifier of the block of the document (0 means the block will be found).
idIdentifier of the document.
void FlushTree ( const C *  obj)
private

Flush the file storing the concept trees of the objects.

Parameters
objPseudo-parameter.
void SeekRecord ( const C *  obj,
size_t  idx 
)
private

Seek the store to the beginning of a record of an object.

Parameters
objPointer to the object.
idxIndex of the object.
bool FindDepthFirstRecord ( const C *  obj,
GConceptRecord rec,
size_t  idx 
)

Find the first record that correspond to a given object starting from a given index.

The first record is not necessary the highest in the hierarchy, since a depth-first search is used.

Parameters
objPointer to the object.
recRecord that will be filled with the result. The concept to be searched must be set.
idxIndex where to start the search.
Returns
true of a record was found.
bool FindRecord ( const C *  obj,
GConceptRecord rec,
size_t  synpos 
)

Find a record at a given syntactic position.

Parameters
objPointer to the object.
recRecord that will be filled with the result.
synposSyntactic position.
Returns
true of a record was found.
bool FindParentRecord ( const C *  obj,
const GConceptRecord search,
GConceptRecord rec 
)

Find the parent record of a given record.

Parameters
objPointer to the object.
searchRecord that contains the record for which the parent must be found.
recRecord that will be filled with the result.
Returns
true of a parent record was found.
bool FindFirstChildRecord ( const C *  obj,
const GConceptRecord search,
GConceptRecord rec,
size_t  idx 
)

Find the first child record that correspond to a given record and starting from a given index.

Parameters
objPointer to the object.
searchRecord that contains the record for which the parent must be found.
recRecord that will be filled with the result.
idxIndex where to start the search.
Returns
true of a record was found.
bool FindNearestRecord ( const C *  obj,
GConceptRecord rec,
size_t  synpos 
)

Find the nearest record at a given syntactic position. In practice, the method searches alternatively before and after the given position.

Parameters
objPointer to the object.
recRecord that will be filled with the result.
synposSyntactic position.
Returns
true of a record was found.
bool FindNearestRecord ( const C *  obj,
GConceptRecord rec,
size_t  synpos,
bool  after 
)

Find the nearest record at a given syntactic position. In practice, the method searches the first record after or before the given position. If no record is found, it searches in the order direction.

Parameters
objPointer to the object.
recRecord that will be filled with the result.
synposSyntactic position.
afterSearch after the position (true) or before it (false)?
Returns
true if a record was found.
bool FindRootRecord ( const C *  obj,
const GConceptRecord rec1,
const GConceptRecord rec2,
GConceptRecord rec 
)

Find the root record (the most common highest record) of two records. If at least one of the node doesn't have a parent, no root node can be found.

Parameters
objPointer to the object.
rec1First record.
rec2Second record.
recRecord that will be filled with the result.
Returns
true if a root node could be found.
size_t GetMinPosRecord ( const C *  obj,
const GConceptRecord rec,
size_t  nbbefore 
)

Find the minimal position centred on a given record and a number of records before.

Parameters
objPointer to the object.
recRecord that contains the record for which the parent must be found.
nbbeforeMaximum number of concept node before.
Returns
a position.
size_t GetMaxPosRecord ( const C *  obj,
const GConceptRecord rec,
size_t  nbafter 
)

Find the maximal position centred on a given record and a number of records after.

Parameters
objPointer to the object.
recRecord that contains the record for which the parent must be found.
nbafterMaximum number of record after.
Returns
a position.
size_t GetMaxPosRecord ( const C *  obj)

Compute the maximal position occupied by a record in an object.

Parameters
objPointer to the object.
Returns
a position.
size_t GetMaxSyntacticPosRecord ( const C *  obj)

Compute the maximal syntactic position occupied by a record in an object.

Parameters
objPointer to the object.
Returns
a syntactic position.
size_t GetNbTotalChildRecords ( const C *  obj,
const GConceptRecord rec 
)

Get the total number of child records (including all the children) of a given record.

Parameters
objPointer to the object.
recRecord that contains the record for which the number must be found.
Returns
a number.

Member Data Documentation

R::RString ObjName
private

Name of the objects.

tObjType Type
private

Type of the objects.

size_t MaxObjs
private

Maximum objects to managed in memory.

R::RKeyValueFile<R::RIntKey>* Desc
private

Description of the objects.

bool CreateIndex
private

Create the index ?

R::RKeyValueFile<R::RIntKey>* Index
private

Index of the objects.

bool CreateTree
private

Create the tree concepts?

R::RKeyValueFile<R::RIntKey>* Tree
private

Tree concepts of the objects.

bool Loaded
private

Are the objects loaded.

R::RNumContainer<size_t,true> tmpRefs
private

Temporary vector of references.

R::RRWLock lObjects
private

Reader/writer lock on the objects.

R::RRWLock lDesc
private

Reader/writer lock on the descriptions.

R::RRWLock lIndex
private

Reader/writer lock on the index.

R::RRWLock lTree
private

Reader/writer lock on the trees.