The qDecoder Project

qEntry.c File Reference

Linked-list Data Structure API. More…


Functions

Q_ENTRYqEntryInit (void)
 Initialize linked-list structure.
const Q_NLOBJqEntryFirst (Q_ENTRY *entry)
 Get first object structure.
const Q_NLOBJqEntryNext (Q_ENTRY *entry)
 Get next object structure.
int qEntryRemove (Q_ENTRY *entry, const char *name)
 Remove matched objects as given name.
bool qEntryPut (Q_ENTRY *entry, const char *name, const void *object, int size, bool update)
 Store object into linked-list structure.
bool qEntryPutStr (Q_ENTRY *entry, const char *name, const char *str, bool update)
 Add string object into linked-list structure.
bool qEntryPutStrf (Q_ENTRY *entry, const char *name, bool update, char *format,…)
 Add formatted string object into linked-list structure.
bool qEntryPutInt (Q_ENTRY *entry, const char *name, int num, bool update)
 Add integer object into linked-list structure.
const void * qEntryGet (Q_ENTRY *entry, const char *name, int *size)
 Find object with given name.
const void * qEntryGetCase (Q_ENTRY *entry, const char *name, int *size)
 Find object with given name.
const void * qEntryGetNext (Q_ENTRY *entry, const char *name, int *size)
 Find next object with given name.
const void * qEntryGetNextCase (Q_ENTRY *entry, const char *name, int *size)
 Find next object with given name.
const void * qEntryGetLast (Q_ENTRY *entry, const char *name, int *size)
 Find lastest matched object with given name.
const char * qEntryGetStr (Q_ENTRY *entry, const char *name)
 Find string object with given name.
const char * qEntryGetStrCase (Q_ENTRY *entry, const char *name)
 Find string object with given name.
const char * qEntryGetStrf (Q_ENTRY *entry, char *format,…)
 Find string object with formatted name.
const char * qEntryGetStrNext (Q_ENTRY *entry, const char *name)
 Find next string object with given name.
const char * qEntryGetStrNextCase (Q_ENTRY *entry, const char *name)
 Find next string object with given name.
const char * qEntryGetStrLast (Q_ENTRY *entry, const char *name)
 Find lastest matched string object with given name.
int qEntryGetInt (Q_ENTRY *entry, const char *name)
 Find integer object with given name.
int qEntryGetIntCase (Q_ENTRY *entry, const char *name)
 Find integer object with given name.
int qEntryGetIntf (Q_ENTRY *entry, char *format,…)
 Find integer object with formatted name.
int qEntryGetIntNext (Q_ENTRY *entry, const char *name)
 Find next integer object with given name.
int qEntryGetIntNextCase (Q_ENTRY *entry, const char *name)
 Find next integer object with given name.
int qEntryGetIntLast (Q_ENTRY *entry, const char *name)
 Find lastest matched integer object with given name.
int qEntryGetNum (Q_ENTRY *entry)
 Get total number of stored objects.
int qEntryGetNo (Q_ENTRY *entry, const char *name)
 Get the stored sequence number of the object.
bool qEntryReverse (Q_ENTRY *entry)
 Reverse-sort internal stored object.
bool qEntryPrint (Q_ENTRY *entry, FILE *out, bool print_object)
 Print out stored objects for debugging purpose.
bool qEntryFree (Q_ENTRY *entry)
 Free Q_ENTRY.
bool qEntrySave (Q_ENTRY *entry, const char *filepath, char sepchar, bool encode)
 Save Q_ENTRY as plain text format.
int qEntryLoad (Q_ENTRY *entry, const char *filepath, char sepchar, bool decode)
 Load and append entries from given filepath.


Detailed Description

Linked-list Data Structure API.

   [Code sample - String]
   // sample data
   struct MY_OBJ *my_obj = getNewMyOjb(); // sample object
   char *my_str = "hello"; // sample string
   int my_int = 1; // sample integer
   // store into linked-list
   Q_ENTRY *entries = qEntryInit();
   entries = qEntryPut(entries, "obj", (void*)my_obj, sizeof(struct MY_OBJ), true);
   entries = qEntryPutStr(entries, "obj", my_str, true);
   entries = qEntryPutInt(entries, "obj", my_int, true);
   // print out
   qEntryPrint(entries, stdout, false);
   // free object
   qEntryFree(entries);
   [Result]

Function Documentation

Q_ENTRY* qEntryInit ( void   ) 

Initialize linked-list structure.

Returns:
a pointer of malloced Q_ENTRY structure in case of successful, otherwise returns NULL.
   Q_ENTRY *entries = qEntryInit();

const Q_NLOBJ* qEntryFirst ( Q_ENTRY entry  ) 

Get first object structure.

Parameters:
entry Q_ENTRY pointer
Returns:
a pointer to internal Q_NLOBJ object structure if successful, otherwise returns NULL

const Q_NLOBJ* qEntryNext ( Q_ENTRY entry  ) 

Get next object structure.

Parameters:
entry Q_ENTRY pointer
Returns:
a pointer to internal Q_NLOBJ object structure if successful, otherwise returns NULL

int qEntryRemove ( Q_ENTRY entry,
const char *  name 
)

Remove matched objects as given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a number of removed objects.

bool qEntryPut ( Q_ENTRY entry,
const char *  name,
const void *  object,
int  size,
bool  update 
)

Store object into linked-list structure.

Parameters:
entry Q_ENTRY pointer
name key name.
object object pointer
size size of the object
update in case of false, just insert. in case of true, remove all same key then insert object if found.
Returns:
true if successful, otherwise returns false.

bool qEntryPutStr ( Q_ENTRY entry,
const char *  name,
const char *  str,
bool  update 
)

Add string object into linked-list structure.

Parameters:
entry Q_ENTRY pointer
name key name.
str string value
update in case of false, just insert. in case of true, remove all same key then insert object if found.
Returns:
true if successful, otherwise returns false.

bool qEntryPutStrf ( Q_ENTRY entry,
const char *  name,
bool  update,
char *  format,
   
)

Add formatted string object into linked-list structure.

Parameters:
entry Q_ENTRY pointer
name key name.
update in case of false, just insert. in case of true, remove all same key then insert object if found.
format formatted string value
Returns:
true if successful, otherwise returns false.

bool qEntryPutInt ( Q_ENTRY entry,
const char *  name,
int  num,
bool  update 
)

Add integer object into linked-list structure.

Parameters:
entry Q_ENTRY pointer
name key name.
num number value
update in case of false, just insert. in case of true, remove all same key then insert object if found.
Returns:
true if successful, otherwise returns false.

const void* qEntryGet ( Q_ENTRY entry,
const char *  name,
int *  size 
)

Find object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
size if size is not NULL, object size will be stored.
Returns:
a pointer of the stored object.
Note:
Because of qEntryGet() returns internal object pointer, you do not modify it directly and do not free it. So if you would like to modify that object, use it after duplicating.

const void* qEntryGetCase ( Q_ENTRY entry,
const char *  name,
int *  size 
)

Find object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
size if size is not NULL, object size will be stored.
Returns:
a pointer of the stored object.

const void* qEntryGetNext ( Q_ENTRY entry,
const char *  name,
int *  size 
)

Find next object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
size if size is not NULL, object size will be stored.
Returns:
a pointer of the stored object.
Note:
qEntryGet() should be called before.

const void* qEntryGetNextCase ( Q_ENTRY entry,
const char *  name,
int *  size 
)

Find next object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
size if size is not NULL, object size will be stored.
Returns:
a pointer of the stored object.
Note:
qEntryGet() should be called before.

const void* qEntryGetLast ( Q_ENTRY entry,
const char *  name,
int *  size 
)

Find lastest matched object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
size if size is not NULL, object size will be stored.
Returns:
a pointer of the stored object.
Note:
If you have objects which have same name. this method can be used to find out lastest matched object.

const char* qEntryGetStr ( Q_ENTRY entry,
const char *  name 
)

Find string object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a pointer of the stored string object.
Note:
String object should be stored by qEntryPutStr().

const char* qEntryGetStrCase ( Q_ENTRY entry,
const char *  name 
)

Find string object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a pointer of the stored string object.

const char* qEntryGetStrf ( Q_ENTRY entry,
char *  format,
   
)

Find string object with formatted name.

Parameters:
entry Q_ENTRY pointer
format name format
Returns:
a pointer of the stored string object.

const char* qEntryGetStrNext ( Q_ENTRY entry,
const char *  name 
)

Find next string object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a pointer of the stored string object.

const char* qEntryGetStrNextCase ( Q_ENTRY entry,
const char *  name 
)

Find next string object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a pointer of the stored string object.

const char* qEntryGetStrLast ( Q_ENTRY entry,
const char *  name 
)

Find lastest matched string object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a pointer of the stored string object.

int qEntryGetInt ( Q_ENTRY entry,
const char *  name 
)

Find integer object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a integer value of the object.
Note:
Integer object should be stored by qEntryPutInt().

int qEntryGetIntCase ( Q_ENTRY entry,
const char *  name 
)

Find integer object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a integer value of the object.

int qEntryGetIntf ( Q_ENTRY entry,
char *  format,
   
)

Find integer object with formatted name.

Parameters:
entry Q_ENTRY pointer
format name format
Returns:
a integer value of the object.

int qEntryGetIntNext ( Q_ENTRY entry,
const char *  name 
)

Find next integer object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a integer value of the object.

int qEntryGetIntNextCase ( Q_ENTRY entry,
const char *  name 
)

Find next integer object with given name.

(case-insensitive)

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a integer value of the object.

int qEntryGetIntLast ( Q_ENTRY entry,
const char *  name 
)

Find lastest matched integer object with given name.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
a integer value of the object.

int qEntryGetNum ( Q_ENTRY entry  ) 

Get total number of stored objects.

Parameters:
entry Q_ENTRY pointer
Returns:
total number of stored objects.

int qEntryGetNo ( Q_ENTRY entry,
const char *  name 
)

Get the stored sequence number of the object.

Parameters:
entry Q_ENTRY pointer
name key name
Returns:
stored sequence number of the object if found, otherwise 0 will be returned.

bool qEntryReverse ( Q_ENTRY entry  ) 

Reverse-sort internal stored object.

Parameters:
entry Q_ENTRY pointer
Note:
This method can be used to improve look up performance. if your application offen looking for last stored object.

bool qEntryPrint ( Q_ENTRY entry,
FILE *  out,
bool  print_object 
)

Print out stored objects for debugging purpose.

Parameters:
entry Q_ENTRY pointer
out output stream FILE descriptor such like stdout, stderr.
print_object true for printing out object value, false for disable printing out object value.

bool qEntryFree ( Q_ENTRY entry  ) 

Free Q_ENTRY.

Parameters:
entry Q_ENTRY pointer
Returns:
always returns true.

bool qEntrySave ( Q_ENTRY entry,
const char *  filepath,
char  sepchar,
bool  encode 
)

Save Q_ENTRY as plain text format.

Parameters:
entry Q_ENTRY pointer
filepath save file path
sepchar separator character between name and value. normally ‘=’ is used.
encode flag for encoding value object. false can be used if the value object is string or integer and has no new line. otherwise true must be set.
Returns:
true if successful, otherwise returns false.

int qEntryLoad ( Q_ENTRY entry,
const char *  filepath,
char  sepchar,
bool  decode 
)

Load and append entries from given filepath.

Parameters:
entry Q_ENTRY pointer
filepath save file path
sepchar separator character between name and value. normally ‘=’ is used
decode flag for decoding value object
Returns:
a number of loaded entries.


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]