PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/DOH/README

#
#! | 118 lines | 99 code | 19 blank | 0 comment | 0 complexity | 3bc61ad45948562599c17798fff1a56b MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. DOH (Dave's Object Hack)
  2. Overview:
  3. ---------
  4. DOH is a small C library that provides a number of simple yet powerful
  5. data structures. The data structures are built around a dynamic typing
  6. model in which any given object is allowed to support one or more
  7. classes of operations. Furthermore, a simple garbage collection
  8. scheme and a variety of interesting library methods are available.
  9. All and all, the operation of DOH makes massive abuse of the C type
  10. system and would probably make the language purists scream and
  11. performance addicts run away in horror. However, I really don't
  12. care--so there! However, for the rest of us, DOH is actually kind of
  13. fun to use. This is only a short description of the methods and is no
  14. way meant to be exhaustive.
  15. Common Operations (for all types)
  16. ---------------------------------
  17. Delete(obj) Decrease the reference count and destroy if zero
  18. Copy(obj) Make a copy of an object.
  19. Clear(obj) Clear an object.
  20. Setscope(obj) Set scope of an object (guru's only)
  21. Str(obj) Create a string representation of obj.
  22. Data(obj) Return pointer to raw data in an object
  23. Char(obj) Convert to a char *
  24. Len(obj) Length of an object
  25. Hash(obj) Hash value (used for mapping)
  26. Cmp(obj1,obj2) Compare two objects.
  27. Name(obj) Return the object name
  28. First(obj) Return first object (iterator)
  29. Next(obj) Return next object
  30. Dump(obj,out) Serialize on out
  31. Load(in) Unserialize from in
  32. First(obj) Iterator
  33. Next(iter) Next iterator
  34. Mapping Operations (for hash table behavior)
  35. --------------------------------------------
  36. Getattr(hash,key) Get an attribute
  37. Setattr(hash,key,value) Set an attribute
  38. Delattr(hash,key) Delete an attribute
  39. First(hash) Get first object (iterator)
  40. Next(hash) Get next object
  41. GetInt(hash,key) Get attribute as an 'int'
  42. SetInt(hash,key,ivalue) Set attribute as an 'int'
  43. GetDouble(hash,key) Get attribute as a 'double'
  44. SetDouble(hash,key,dvalue) Set Attribute as a 'double'
  45. GetChar(hash,key) Get attribute as a 'char *'
  46. Sequence Operations
  47. -------------------
  48. Getitem(list,index) Get an item
  49. Setitem(list,index,val) Set an item
  50. Delitem(list,index,val) Delete an item
  51. Insert(list,index,val) Insert an item
  52. Append(list,val) Append to end
  53. Push(list,val) Insert at beginning
  54. File Operations
  55. ---------------
  56. Read(obj,buffer,len) Read data
  57. Write(obj,buffer,len) Write data
  58. Getc(obj) Get a character
  59. Putc(ch,obj) Put a character
  60. Ungetc(ch,obj) Put character back on input stream
  61. Seek(obj,offset,whence) Seek
  62. Tell(obj) Return file pointer
  63. Close(obj) Close
  64. String Operations
  65. -----------------
  66. Replace(obj, orig, rep, flags) Replace occurences of orig with rep.
  67. Chop(obj) Remove trailing whitespace
  68. flags is one of the following:
  69. DOH_REPLACE_ANY
  70. DOH_REPLACE_NOQUOTE
  71. DOH_REPLACE_ID
  72. DOH_REPLACE_FIRST
  73. Callable Operations
  74. -------------------
  75. Call(obj, args) Perform a function call with arguments args.
  76. Miscellaneous library functions
  77. -------------------------------
  78. NewScope() Create a new scope
  79. DelScope(s) Delete scope s
  80. Readline(in) Read a line of input from in
  81. Printf(out,fmt,...) Formatted output
  82. DohEncoding(name, fn) Register a format encoding for Printf
  83. Currently Available datatypes
  84. ------------------------------
  85. NewString(char *initial) Strings
  86. NewHash() Hash
  87. NewList() List
  88. NewVoid(void *ptr, void (*del)(void *)) Void
  89. NewFile(char *filename, char *mode, List *newfiles) File
  90. NewCallable(DOH *(*func)(DOH *, DOH *)) Callable object
  91. Odds and ends:
  92. 1. All objects are of type 'DOH *'
  93. 2. When in doubt, see rule (1)
  94. 3. In certain cases, DOH performs implicit conversions
  95. of 'char *' to an appropriate DOH string representation.
  96. For operations involving files, DOH works with many
  97. kinds of objects including FILE *, DOH File objects,
  98. and DOH strings. Don't even ask how this works.
  99. 4. More complete documentation is forthcoming.