Xpace
collator.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file index/collator/collator.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_COLLATOR_H
13 #define XPACE_COLLATOR_H
14 
15 #include "base/sharedimpl.h"
16 #include "base/config.h"
17 #include "base/exception.h"
18 
19 namespace Xpace
20 {
21  // ================================ EXCEPTIONS ==============
22 
24  {
25  public:
26  /// @param config the Collator's Configuration
27  /// @reason what caused the failure (e.g. File_Cant_Open)
29  (const String config,
30  const Exception reason = Exception()) :
31  Exception("Can't construct collator from XML fragment \"%1\".", reason)
32  {
33  addParam(config);
34  }
35  };
36 
38  {
39  public:
41  (String collatorType,
42  String termType) :
43  Exception("Collator %1 cannot process term of type %2.")
44  {
45  addParam(collatorType);
46  addParam(termType);
47  }
48  };
49  #define COLLATOR_TERM_MISMATCH(term) CollatorTermMismatch(typeid(*this).name(), typeid(term).name())
50 
52  {
53  public:
55  (size_t len) :
56  Exception("Collator term too long (%1).")
57  {
58  addParam(String().setNum(len));
59  }
60  };
61 
63  {
64  public:
67  Exception("Collator value (%1) out of range.")
68  {
69  addParam(String().setNum(value));
70  }
71  };
72 
73  // ================================ KEYS ====================
74 
75  // Allocator implementation for a temporary key
77  {
78  public:
79  byte* alloc
80  (size_t size)
81  {
82  assert(!hmem.get());
83  return reinterpret_cast<byte*>((size < sizeof(smem)) ? smem : (hmem.reset(new uint64[size >> 3]), hmem.get()));
84  }
85 
86  private:
87  uint64 smem[128 / sizeof(uint64)];
88  std::unique_ptr<uint64> hmem;
89  bool adjusted;
90  };
91 
92  // ================================ BUFFER ==================
93 
94  // Allocator implementation for a contiguous buffer
96  {
97  public:
99  (byte* b) :
100  buf(b)
101  {
102  }
103 
104  byte* alloc
105  (size_t size)
106  {
107  byte* ret(buf);
108  buf += size;
109  return ret;
110  }
111 
112  byte* getBuf
113  ()
114  const
115  {
116  return buf;
117  }
118 
119  private:
120  byte* buf;
121  };
122 
123  // ================================ TAGS ====================
124 
126  {
127  static const char* FORMAT_TAG;
128  static const char* PRECISION_TAG;
129  };
130 
131 } // namespace
132 
133 #endif
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
uint const Xpace_Char8 size_t len
Definition: table_c.h:180
unsigned long long uint64
Definition: types.h:87
Copyright (C) 2012 Xpace, LLC.
void addParam(const String &p)
Add a parameter to this exception The first parameter added will replace &#39;%1&#39; in the template...
uint int64 value
Definition: table_c.h:159
long long int64
Definition: types.h:86
CantCreateCollator(const String config, const Exception reason=Exception())
Definition: collator.h:29
Xpace project main namespace
Definition: datetime.h:18
static const char * FORMAT_TAG
Definition: collator.h:127
static const char * PRECISION_TAG
Definition: collator.h:128
uchar byte
Definition: types.h:74

current as of Wed Jun 10 2026 12:00:05