2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
qfplist.h
|
|
|
|
|
|
|
|
Property list management types and prototypes
|
|
|
|
|
2001-06-19 02:10:47 +00:00
|
|
|
Copyright (C) 2000 Jeff Teunissen <deek@d2dc.net>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
2001-06-19 02:10:47 +00:00
|
|
|
#ifndef __QF_qfplist_h_
|
|
|
|
#define __QF_qfplist_h_
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** \defgroup qfplist Property lists
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup utils
|
2004-11-11 11:18:00 +00:00
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
#include "QF/qtypes.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-01-06 11:09:40 +00:00
|
|
|
/**
|
|
|
|
There are four types of data that can be stored in a property list:
|
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
<dl>
|
|
|
|
<dt>QFDictionary</dt> <dd>A list of values, each associated with a
|
|
|
|
key (a C string).</dd>
|
|
|
|
<dt>QFArray</dt> <dd>A list of indexed values</dd>
|
|
|
|
<dt>QFString</dt> <dd>A string.</dd>
|
|
|
|
<dt>QFBinary</dt> <dd>Random binary data.</dd>
|
|
|
|
</dl>
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
In textual form, a dictionary looks like:
|
2010-08-20 04:10:37 +00:00
|
|
|
\code
|
2004-01-06 11:09:40 +00:00
|
|
|
{
|
|
|
|
key = value;
|
|
|
|
}
|
2010-08-20 04:10:37 +00:00
|
|
|
\endcode
|
2004-01-06 11:09:40 +00:00
|
|
|
An array looks like:
|
2010-08-20 04:10:37 +00:00
|
|
|
\code
|
2004-01-06 11:09:40 +00:00
|
|
|
(
|
|
|
|
value1,
|
|
|
|
value2
|
|
|
|
)
|
2010-08-20 04:10:37 +00:00
|
|
|
\endcode
|
2004-01-06 11:09:40 +00:00
|
|
|
An unquoted string may contain only alphanumeric characters and/or the
|
2010-08-20 04:10:37 +00:00
|
|
|
underscore character, <code>_</code>. Quoted strings may contain
|
|
|
|
whitespace, C escape sequences, and so on. The quote character is
|
|
|
|
<code>\"</code>. Optionally, Python style long strings
|
|
|
|
(<code>\"\"\"...\"\"\"</code>) may be used, allowing for unquoted
|
|
|
|
<code>"</code> quotes in the string.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2007-10-13 07:55:58 +00:00
|
|
|
<!-- in the following paragraph, the \< and \> are just < and >. the \ is
|
2004-01-17 08:09:30 +00:00
|
|
|
for doxygen -->
|
2010-08-20 04:10:37 +00:00
|
|
|
QFBinary data is hex-encoded and contained within angle brackets, \c \<
|
|
|
|
\c \>. The length of the encoded data must be an even number, so while
|
|
|
|
\c \<FF00\> is valid, \c \<F00\> isn't.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
Property lists may contain C-style or BCPL-style comments.
|
|
|
|
*/
|
2010-08-20 04:10:37 +00:00
|
|
|
typedef enum {QFDictionary, QFArray, QFBinary, QFString} pltype_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
/** Generic property list item.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
All inspection and manipulation is to be done via the accessor functions.
|
2001-06-19 02:10:47 +00:00
|
|
|
*/
|
2010-08-20 04:10:37 +00:00
|
|
|
typedef struct plitem_s plitem_t;
|
2001-08-01 06:51:06 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Create an in-memory representation of the contents of a property list.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param string the saved plist, as read from a file.
|
|
|
|
|
|
|
|
\return Returns an object equivalent to the passed-in string.
|
2004-11-11 11:18:00 +00:00
|
|
|
\note You are responsible for freeing the object returned.
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
plitem_t *PL_GetPropertyList (const char *string);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Create a property list string from the in-memory representation.
|
|
|
|
|
|
|
|
\param pl the in-memory representation
|
|
|
|
\return the text representation of the property list
|
|
|
|
\note You are responsible for freeing the string returned.
|
|
|
|
*/
|
|
|
|
char *PL_WritePropertyList (plitem_t *pl);
|
|
|
|
|
|
|
|
/** Retrieve the type of an object.
|
|
|
|
|
|
|
|
\param item The object
|
|
|
|
\return the type of the object
|
|
|
|
*/
|
|
|
|
pltype_t PL_Type (plitem_t *item);
|
|
|
|
|
|
|
|
/** Retrieve a string from a string object.
|
|
|
|
|
|
|
|
\param string The string object
|
|
|
|
\return pointer to the actual string value or NULL if string isn't a
|
|
|
|
string.
|
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
|
|
|
const char *PL_String (plitem_t *string);
|
|
|
|
|
|
|
|
/** Retrieve a value from a dictionary object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to retrieve a value from
|
|
|
|
\param key The unique key associated with the value
|
2004-11-11 11:18:00 +00:00
|
|
|
\return the value associated with the key, or NULL if not found or dict
|
|
|
|
isn't a dictionary.
|
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
2004-01-06 11:09:40 +00:00
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
plitem_t *PL_ObjectForKey (plitem_t *dict, const char *key);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2006-12-18 13:11:26 +00:00
|
|
|
/** Remove a value from a dictionary object.
|
2006-12-09 06:00:36 +00:00
|
|
|
|
|
|
|
\param dict The Dictionary to remove the value from
|
|
|
|
\param key The unique key associated with the value to be removed
|
|
|
|
\return the value associated with the key, or NULL if not found or dict
|
|
|
|
isn't a dictionary.
|
|
|
|
\note You are responsible for freeing the returned object.
|
|
|
|
*/
|
2006-12-18 13:11:26 +00:00
|
|
|
plitem_t *PL_RemoveObjectForKey (plitem_t *dict, const char *key);
|
2006-12-09 06:00:36 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve a value from an array object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param array The array to get the value from
|
2004-01-07 20:06:15 +00:00
|
|
|
\param index The index within the array to retrieve
|
2004-11-11 11:18:00 +00:00
|
|
|
\return the value associated with the key, or NULL if not found or array
|
|
|
|
isn't an array.
|
|
|
|
\note You are NOT responsible for freeing the returned object. It will
|
2004-01-06 11:09:40 +00:00
|
|
|
be destroyed when its container is.
|
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
plitem_t *PL_ObjectAtIndex (plitem_t *array, int index);
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve a list of all keys in a dictionary.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to list
|
2004-11-11 11:18:00 +00:00
|
|
|
\return an Array containing Strings or NULL if dict isn't a dictionary
|
|
|
|
\note You are responsible for freeing this array.
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
plitem_t *PL_D_AllKeys (plitem_t *dict);
|
2004-01-06 11:09:40 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Retrieve the number of keys in a dictionary.
|
2004-02-07 07:47:23 +00:00
|
|
|
|
|
|
|
\param dict The dictionary to get the number of keys of.
|
|
|
|
|
|
|
|
\return Returns the number of keys in the dictionary.
|
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
int PL_D_NumKeys (plitem_t *dict);
|
2004-02-07 07:47:23 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Add a key/value pair to a dictionary.
|
2004-01-07 06:19:11 +00:00
|
|
|
|
2004-01-07 20:06:15 +00:00
|
|
|
\param dict The dictionary to add the key/value pair to
|
2004-01-07 06:19:11 +00:00
|
|
|
\param key The key of the key/value pair to be added to the dictionary
|
|
|
|
\param value The value of the key/value pair to be added to the dictionary
|
|
|
|
|
|
|
|
\return true on success, false on failure
|
|
|
|
|
2006-12-09 06:00:36 +00:00
|
|
|
\note the dictionary becomes the owner of the value.
|
2004-01-07 06:19:11 +00:00
|
|
|
*/
|
2006-12-09 06:00:36 +00:00
|
|
|
qboolean PL_D_AddObject (plitem_t *dict, const char *key, plitem_t *value);
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
/** Add an item to an array.
|
2004-01-09 03:32:00 +00:00
|
|
|
|
|
|
|
\param array The array to add the item to
|
|
|
|
\param item The item to be added to the array
|
|
|
|
|
|
|
|
\return true on success, false on failure
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
\note the array becomes the owner of the added item.
|
2004-01-09 03:32:00 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
qboolean PL_A_AddObject (plitem_t *array, plitem_t *item);
|
|
|
|
|
|
|
|
/** Retrieve the number of items in an array.
|
2004-01-09 03:32:00 +00:00
|
|
|
|
2004-02-07 07:47:23 +00:00
|
|
|
\param array The array to get the number of objects in
|
|
|
|
|
|
|
|
\return number of objects in the array
|
|
|
|
*/
|
|
|
|
int PL_A_NumObjects (plitem_t *array);
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Insert an item into an array before the specified location.
|
|
|
|
|
2004-01-09 03:32:00 +00:00
|
|
|
\param array The array to add the item to
|
|
|
|
\param item The item to be added to the array
|
|
|
|
\param index The location at which to insert the item into the array
|
|
|
|
|
|
|
|
\return true on success, false on failure
|
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
\note the array becomes the owner of the added item.
|
2004-01-09 03:32:00 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
qboolean PL_A_InsertObjectAtIndex (plitem_t *array, plitem_t *item, int index);
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2006-12-09 02:33:08 +00:00
|
|
|
/** Remove a value from an array object.
|
|
|
|
The array items will be shuffled to fill the resulting hole.
|
|
|
|
|
|
|
|
\param array The array to get the value from
|
|
|
|
\param index The index within the array to remove
|
|
|
|
\return the value associated with the index, or NULL if not found or array
|
|
|
|
isn't an array.
|
|
|
|
\note You are responsible for freeing the returned object.
|
|
|
|
*/
|
|
|
|
plitem_t *PL_RemoveObjectAtIndex (plitem_t *array, int index);
|
|
|
|
|
2010-08-20 04:10:37 +00:00
|
|
|
/** Create a new dictionary object.
|
|
|
|
The dictionary will be empty.
|
|
|
|
\return the new dictionary object
|
|
|
|
*/
|
2003-03-18 19:15:31 +00:00
|
|
|
plitem_t *PL_NewDictionary (void);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new array object.
|
|
|
|
The array will be empty.
|
|
|
|
\return the new array object
|
|
|
|
*/
|
2003-03-18 19:15:31 +00:00
|
|
|
plitem_t *PL_NewArray (void);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new data object from the given data.
|
2010-08-20 04:21:22 +00:00
|
|
|
Takes ownership of the given data.
|
2010-08-20 04:10:37 +00:00
|
|
|
\param data pointer to data buffer
|
|
|
|
\param size number of bytes in the buffer
|
|
|
|
\return the new dictionary object
|
2010-08-20 04:21:22 +00:00
|
|
|
\note The data will be freed via free() when the item is freed.
|
2010-08-20 04:10:37 +00:00
|
|
|
*/
|
2010-08-20 04:21:22 +00:00
|
|
|
plitem_t *PL_NewData (void *data, size_t size);
|
2010-08-20 04:10:37 +00:00
|
|
|
|
|
|
|
/** Create a new string object.
|
|
|
|
Makes a copy of the given string.
|
|
|
|
\param str C string to copy
|
|
|
|
\return the new dictionary object
|
|
|
|
*/
|
|
|
|
plitem_t *PL_NewString (const char *str);
|
2003-03-18 19:15:31 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
/** Free a property list object.
|
2004-01-06 11:09:40 +00:00
|
|
|
|
|
|
|
This function takes care of freeing any referenced property list data, so
|
2010-01-13 06:42:26 +00:00
|
|
|
call it only on top-level objects.
|
2004-11-11 11:18:00 +00:00
|
|
|
|
|
|
|
\param item the property list object to be freed
|
2004-01-06 11:09:40 +00:00
|
|
|
*/
|
2004-11-11 11:18:00 +00:00
|
|
|
void PL_Free (plitem_t *item);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-11 11:18:00 +00:00
|
|
|
//@}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-19 02:10:47 +00:00
|
|
|
#endif // __QF_qfplist_h_
|