String.xcc

Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com)

Copyright 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.

This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.

An String is a single-copy, non-mutable object, that can contain arbitrary data. String(s) pointers are equal only when the underlying data is the same. The single copy property of String(s) is only relative to a particular StringTable (String Table). The StringTable itself organizes its String(s) into a balanced binary tree search structure.

String— A single-copy, non-mutable object, maintained in a StringTable.

An String is aligned to intptr_t alignment constraints, and its storage is rounded up to sizeof(intptr_t). The leftover storage bytes are cleared.

typedef const char *String;
String_ENTRY— Access the underlying StringTableEntry of this String.
#define String_ENTRY(this) (((StringTableEntry)((void*)(this))) - 1)
String_Size— The memory size needed by this String
#define String_Size(data, length, leaf) ( \
  StringTableEntry_DATA(leaf) != NULL? \
      ((length) + sizeof(intptr_t) - 1) & -sizeof(intptr_t): 0 \
)
StringTableEntry— Information to manage a String into a StringTable.
struct StringTableEntry_ {
  //@args       const void *data, int32_t length, StringTableEntry leaf
  struct StringTableEntry_ *LEFT;       // The left kid in the binary search tree.
  struct StringTableEntry_ *RIGHT;      // The right kid in the binary search tree.
  uint32_t HASHED;      // The hashed data.
  //@access PRIORITY    (StringTableEntry_HASHED(this))
  int32_t LENGTH;       // The data length.
  const void *DATA;     // Where the data is located.
  //@access STRING      ((String)((StringTableEntry)(this) + 1))
};
String_hashed— return the hashed value of this String.
//
static inline uint32_t
String_hashed(String this)
{
  StringTableEntry entry = String_ENTRY(this);
  return StringTableEntry_HASHED(entry);
}
String_length— return the length of this String.
static inline int32_t
String_length(String this)
{
  StringTableEntry entry = String_ENTRY(this);
  return StringTableEntry_LENGTH(entry);
}
String_data— return the data of this String.
static inline const void *
String_data(String this)
{
  StringTableEntry entry = String_ENTRY(this);
  return StringTableEntry_DATA(entry);
}
StringTable— Implements a table of String(s) without duplicates.
copies
If set, the string will be copied when entered in the StringTable.
struct StringTable_ {
  //@args       Memory memory, bool copies
  Memory MEMORY;        // Where the String(s) are allocated.
  struct StringTableEntry_ *ROOT;
  StringTableEntry_ LEAF_;
  //@access LEAF        StringTable__LEAF_(this)
  //@access COPIES      (StringTableEntryDATA(StringTable_LEAF(this)) == (const void *)1)
  uint32_t COUNT;
};

StringTable_memory -- This StringTable Memory.

static inline Memory
StringTable_memory(const_StringTable this)
{
  return StringTable_MEMORY(this);
}
static inline bool
StringTable_copies(const_StringTable this)
{
  const_StringTableEntry leaf = StringTable_LEAF(this);
  return StringTableEntry_DATA(leaf) != NULL;
}
StringTable_search— Search the String corresponding to data.
Return
The String corresponding to data, or NULL if not found.
String
StringTable_search(const_StringTable this, const void *data, int32_t length);
StringTable_insert— Insert data into this table, unless it's already there.
String
StringTable_insert(StringTable this, const void *data, int32_t length);
StringTable_remove— Remove data from the tree if it's there.
bool
StringTable_remove(StringTable this, const void *data, int32_t length);
StringTable_map— Map the StringTable String(s) using the supplied map function.
map
The function that will be called for each String in the StringTable. First argument of (map) is the current String. Second argument of (map) is the va_list corresponding to the ... arguments of StringTable_map.
...
The other arguments if any to be passed to (*map) as va_list.
void
StringTable_map(StringTable this, void (*map)(String, va_list), ...);
String_S— Make a string from %s.
String
StringTable_S(StringTable this, const char *name);
String_D— Make a string from %lld.
String
StringTable_D(StringTable this, int64_t lld);
StringStoreItem— Information attached to a String in a StringStore.
struct StringStoreItem_ {
  //@args       int32_t length, struct StringStoreItem_ *next
  int32_t LENGTH;
  struct StringStoreItem_ *NEXT;
};
StringStore— Simple store to save strings.
struct StringStore_ {
  //@args       Memory memory
  Memory MEMORY;
  StringStoreItem FIRST;
};
StringStore_memory— This StringStore Memory.
static inline Memory
StringStore_memory(const_StringStore this)
{
  return StringStore_MEMORY(this);
}
StringStore_first— For use in StringStore_FOREACH_String.
static inline StringStoreItem
StringStore_first(const_StringStore this)
{
  return StringStore_FIRST(this);
}
StringStore_FOREACH_String— Iterate this StringStore String(s).
#define StringStore_FOREACH_String(this, string) { \
  StringStoreItem StringStore_ITEM = StringStore_first(this); \
  while (StringStore_ITEM != NULL) { \
    StringStoreItem StringStore_NEXT = StringStoreItem_NEXT(StringStore_ITEM); \
    String string = (String)(StringStore_ITEM + 1);
#define StringStore_ENDEACH_String \
    StringStore_ITEM = StringStore_NEXT; \
  } \
}
StringStore_push— Push a String onto this StringStore.
String
StringStore_push(StringStore this, const void *data, int32_t length);
StringStore_S— Push a null-teminated C string onto this StringStore.
static inline String
StringStore_S(StringStore this, const char *name)
{
  int32_t length = strlen(name) + 1;
  return StringStore_push(this, name, length);
}