Subversion Repositories Kolibri OS

Rev

Rev 5959 | Rev 5974 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_COLLECTION_H
  2. #define INCLUDE_COLLECTION_H
  3. #print "[include <collection.h>]\n"
  4.  
  5. struct collection
  6. {
  7.         int realloc_size, count;
  8.         dword data_start;
  9.         dword data_cur_pos;
  10.         dword data_size;
  11.         dword element_offset[4090];
  12.         int add();
  13.         dword get();
  14.         void drop();
  15.         void increase_data_size();
  16.  
  17. };
  18.  
  19. void collection::increase_data_size() {
  20.         int filled_size;
  21.         if (realloc_size<4096) realloc_size = 4096;
  22.         if (!data_size) {
  23.                 data_size = realloc_size;
  24.                 data_start = malloc(realloc_size);             
  25.         }
  26.         else {
  27.                 data_size = data_size + realloc_size;
  28.                 data_start = realloc(data_start, data_size);
  29.         }
  30. }
  31.  
  32. int collection::add(dword in) {
  33.         if (count >= 4090) return 0;
  34.         if (data_cur_pos+strlen(in)+2 > data_size) {
  35.                 increase_data_size();
  36.                 add(in);
  37.                 return;
  38.         }
  39.         strcpy(data_start+data_cur_pos, in);
  40.         element_offset[count] = data_cur_pos;
  41.         data_cur_pos += strlen(in) + 1;
  42.         count++;
  43.         return 1;
  44. }
  45.  
  46. dword collection::get(dword pos) {
  47.         return data_start + element_offset[pos];
  48. }
  49.  
  50. void collection::drop() {
  51.         if (data_start) free(data_start);
  52.         data_size = data_start = data_cur_pos = count = 0;
  53. }
  54.  
  55. #endif