JASSv2
document.h
Go to the documentation of this file.
1 /*
2  DOCUMENT.H
3  ----------
4  Copyright (c) 2016 Andrew Trotman
5  Released under the 2-clause BSD license (See:https://en.wikipedia.org/wiki/BSD_licenses)
6 */
13 #pragma once
14 
15 #include "slice.h"
16 #include "allocator_pool.h"
17 
18 namespace JASS
19  {
20  /*
21  CLASS DOCUMENT
22  --------------
23  */
31  class document
32  {
33  private:
34  static const size_t default_allocation_size = 8192;
35 
36  protected:
38 
39  public:
44 
45  public:
46  /*
47  DOCUMENT::DOCUMENT()
48  --------------------
49  */
54  default_allocator(default_allocation_size),
55  primary_key_allocator(default_allocator),
56  contents_allocator(default_allocator)
57  {
58  /*
59  Nothing
60  */
61  }
62 
63  /*
64  DOCUMENT::DOCUMENT()
65  --------------------
66  */
70  document(class allocator &memory_source) :
71  primary_key_allocator(default_allocator),
72  contents_allocator(memory_source)
73  {
74  /*
75  Nothing
76  */
77  }
78 
79  /*
80  DOCUMENT::ISEMPTY()
81  -------------------
82  */
87  bool isempty(void)
88  {
89  return contents.size() == 0;
90  }
91 
92  /*
93  DOCUMENT::REWIND()
94  ------------------
95  */
99  void rewind(void)
100  {
101  primary_key = slice();
102  contents = slice();
103  contents_allocator.rewind();
104  primary_key_allocator.rewind();
105  }
106 
107  /*
108  DOCUMENT::UNITTEST()
109  --------------------
110  */
114  static void unittest(void)
115  {
116  document document1;
117  allocator_pool pool;
118  document document2(pool);
119 
120  puts("document::PASSED");
121  }
122  };
123  }
C++ slices (string-descriptors)
Definition: slice.h:27
Container class representing a document through the indexing pipeline.
Definition: document.h:31
static const size_t default_allocation_size
The default size of the allocation unit within the document.
Definition: document.h:34
document()
Constructor using an allocator local to this object (useful when the object needs to contain its own ...
Definition: document.h:53
slice primary_key
The external primary key (e.g. TREC DOCID, or filename) of the document (or empty if that is meaningl...
Definition: document.h:42
static void unittest(void)
Unit test this class.
Definition: document.h:114
void rewind(void)
Free up all resources assocuated with this object and make it ready for re-use.
Definition: document.h:99
bool isempty(void)
Check to see whether this is an empty document.
Definition: document.h:87
slice contents
The contents of the document (or likewise).
Definition: document.h:43
Simple block-allocator that internally allocates a large chunk then allocates smaller blocks from thi...
Definition: allocator_pool.h:61
Virtual base class for C style allocators.
Definition: allocator.h:33
virtual void rewind(void)=0
Throw away (without calling delete) all objects allocated in the memory space of this allocator Delet...
document(class allocator &memory_source)
Constructor using an allocator specified (useful when the object needs to allocate memory in a specif...
Definition: document.h:70
Simple block-allocator that internally allocates a large chunk then allocates smaller blocks from thi...
Slices (also known as string-descriptors) for C++.
allocator_pool default_allocator
If a document is created without a specified allocator then use a pool allocator. ...
Definition: document.h:37
allocator & contents_allocator
If memory is needed for the document contents then allocate from here.
Definition: document.h:41
Definition: compress_integer_elias_delta_simd.c:23
size_t size(void) const
Return the length of this slice.
Definition: slice.h:256
allocator & primary_key_allocator
If memory is needed for the primary key then allocate from here.
Definition: document.h:40