ARB
gb_storage.h
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : gb_storage.h //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #ifndef GB_STORAGE_H
12 #define GB_STORAGE_H
13 
14 #ifndef GB_DATA_H
15 #include "gb_data.h"
16 #endif
17 
18 CONSTEXPR_INLINE bool store_inside_entry(int size, int memsize) {
19  // returns true if data can be stored inside GBENTRY
20  return size<256 && memsize<SIZOFINTERN;
21 }
22 
23 inline char *GBENTRY::alloc_data(long Size, long Memsize) {
24  char *mem;
26  gb_assert(implicated(stored_external(), !data())); // would leak memory
27 
28  if (store_inside_entry(Size, Memsize)) {
30 
31  info.istr.size = (unsigned char)Size;
32  info.istr.memsize = (unsigned char)Memsize;
33 
34  mem = data();
35  }
36  else {
38 
39  info.ex.size = Size;
40  info.ex.memsize = Memsize;
41 
42  mem = (char*)gbm_get_mem((size_t)Memsize, GB_GBM_INDEX(this));
43  info.ex.set_data(mem);
44  }
45  return mem;
46 }
47 
48 class GBENTRY_memory : virtual Noncopyable {
49  GBENTRY *gbe;
50  char *mem;
51 public:
52  GBENTRY_memory(GBENTRY *gb_entry, long size, long memsize)
53  : gbe(gb_entry),
54  mem(gbe->alloc_data(size, memsize))
55  {}
57  operator char*() { return mem; }
58 };
59 
60 inline void GBENTRY::insert_data(const char *Data, long Size, long Memsize) {
61  gb_assert(Data);
62  memcpy(GBENTRY_memory(this, Size, Memsize), Data, Memsize);
63 }
64 
65 #else
66 #error gb_storage.h included twice
67 #endif // GB_STORAGE_H
CONSTEXPR_INLINE bool store_inside_entry(int size, int memsize)
Definition: gb_storage.h:18
long memsize
Definition: gb_data.h:29
#define GB_GBM_INDEX(gbd)
Definition: gb_data.h:127
unsigned char size
Definition: gb_data.h:39
#define implicated(hypothesis, conclusion)
Definition: arb_assert.h:289
unsigned char memsize
Definition: gb_data.h:38
gb_flag_types2 flags2
Definition: gb_data.h:135
gb_data_base_type_union info
Definition: gb_data.h:204
void insert_data(const char *Data, long Size, long Memsize)
Definition: gb_storage.h:60
GB_INTern_strings istr
Definition: gb_data.h:49
#define CONSTEXPR_INLINE
Definition: cxxforward.h:111
#define SIZOFINTERN
Definition: gb_data.h:25
void index_re_check_in()
Definition: gb_data.h:235
char * alloc_data(long Size, long Memsize)
Definition: gb_storage.h:23
void * gbm_get_mem(size_t size, long index)
Definition: gb_memory.h:130
unsigned int is_indexed
Definition: gb_data.h:88
gb_extern_data ex
Definition: gb_data.h:51
char * data()
Definition: gb_data.h:219
void mark_as_intern()
Definition: gb_data.h:208
#define gb_assert(cond)
Definition: arbdbt.h:11
bool stored_external() const
Definition: gb_data.h:211
GBENTRY_memory(GBENTRY *gb_entry, long size, long memsize)
Definition: gb_storage.h:52
void mark_as_extern()
Definition: gb_data.h:209
void set_data(char *data)
Definition: gb_data.h:33