Xpace
table.h
Go to the documentation of this file.
1 
2 /**************************************************************
3  **
4  ** @file data/Store/table.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 
13 #if !defined XPACE_TABLE_H
14 #define XPACE_TABLE_H
15 
16 #include <memory>
17 #include <functional>
18 
19 #include "data/data.h"
20 
21 #include "base/sharedimpl.h"
22 
23 namespace Xpace
24 {
26  {
27  public :
28  static const char* TAG(); ///< Configuration tag for a Table
29  static const char* NAME_TAG; ///< Configuration tag for a Table's Name
30 
31  /// @param config the Table's Configuration; must include TAG, dd, di, and dt
32  /// @param access how the Table will be opened
33  /// @throw File_Cant_Open
34  /// @throw File_Cant_Read
35  explicit Table
36  (const String& config,
38 
39  /// @param store the Table's store file
40  /// @param refs the Table's refs file (if any)
41  /// @param map the Table's map file (if any)
42  /// @param access how the Table will be opened
43  /// @param overwrite start fresh if true; append if false
44  /// @param test compare on read if true; append on read if false
45  /// @param name if overwrite, name the table this
46  Table
47  (const String& store,
48  const String& refs,
49  const String& map,
51  bool overwrite = false,
52  bool test = false,
53  const String& name = String());
54 
55  /// @return true if the table is empty or does not exist
56  bool operator!
57  ()
58  const;
59 
60  ///@ close the table, including its Sink (if any)
61  void close
62  ();
63 
64  /// @return the table's name
65  String getName
66  ()
67  const;
68 
69  ///@ return the table's configuration
70  String getConfig
71  ()
72  const;
73 
74  /// Get a column's configuration
75  /// @param col the column number
76  /// @return the column's Configuration
77  String getColumnConfig
78  (uint col)
79  const;
80 
81  /// Get a column name from a column number
82  /// @param the column number
83  /// @return the column number, String() if not found
84  String getColumnName
85  (uint col)
86  const;
87 
88  /// Get a column type from a column number
89  /// @param the column number
90  /// @return the column type, none if not found
91  DerivedDataType getColumnType
92  (uint col)
93  const;
94 
95  /// Get a column from a column name
96  /// @param the column name
97  /// @return the column number, ~0 if not found
98  uint getColumnNumber
99  (const String& name)
100  const;
101 
102  /// @return the number of rows in the table
103  uint64 getRowCount
104  ()
105  const;
106  /// @for compatibility with Store
107  uint64 getDocCount
108  ()
109  const
110  {
111  return getRowCount();
112  }
113 
114  /// @return the number of columns in the table
115  uint getColumnCount
116  ()
117  const;
118 
119  // ------------------------------ Source ------------------
120 
121  /// @A read-only cursor into a table, parameterized on column
123 
124  /// @Memory management for a Source
126  {
127  void operator()
128  (Source*);
129  };
130  typedef std::unique_ptr<Source, SourceDeleter> SourcePtr;
131 
132  /// create a Source
133  /// @param row start at this row
134  /// @return the Source
135  SourcePtr createSource
136  (uint64 row = 0)
137  const;
138 
139  // ------------------------------ Sink --------------------
140 
141  /// A write-only, forward cursor into a table
142  class XPACE_EXPORT Sink : public Xpace::Sink<uint>
143  {
144  public:
145  /// Add a column by name
146  /// @param name the name of the column
147  /// @param type the type of the column
148  /// @param columnNum a proposed column number
149  /// @retval added true iff the field or column was added
150  /// @returns the actual column number, ~0 to stop
151  virtual uint add
152  (const String& name,
154  uint columnNum,
155  bool* added = 0) override
156  = 0;
157 
159  };
160 
161  /// @return the (only) Sink to this table
162  Sink* getSink
163  ();
164 
165  /// Call a Sink for each column in this table
166  /// @param sink called for each cell
167  /// @param columns if not empty, return these columns in this order
168  /// @return true iff act always returned true, false otherwise
169  bool forEachColumn
170  (Sink* sink,
171  const std::vector<uint>& columns = std::vector<uint>())
172  const;
173 
174  /// Call a Sink for each cell in row/column order
175  /// @param sink called for each cell
176  /// @param columns if not empty, return these columns in this order
177  /// @param status called for each row, return interval before next call
178  /// @return true iff sink always returned true, false otherwise
179  bool forEach
180  (Sink* sink,
181  const std::vector<uint>& columns = std::vector<uint>(),
182  StatusCallback status = defaultStatus)
183  const;
184 
185  /// Can't open a Table
186  class cantOpen : public Exception
187  {
188  public:
189  /// @param config the configuration of the table
190  /// @param reason why it couldn't be opened (e.g., File_Cant_Open)
191  cantOpen
192  (const String name,
193  const String& config,
194  const Exception reason = Exception());
195  };
196 
197  /// Can't create a Source
199  {
200  public:
201  /// @param row the row at which the creation failed
203  (uint64 row);
204  };
205 
207  };
208 };
209 
210 #endif
uint * columns
Definition: table_c.h:340
const Xpace_Char16 Xpace_Data_Type type
Definition: table_c.h:141
A low-level data holder.
Definition: types_c.h:82
unsigned int uint
Definition: types.h:75
const Xpace_Char16 Xpace_Data_Type uint bool * added
Definition: table_c.h:141
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
management for a Source
Definition: table.h:125
const Xpace_Char16 Xpace_Data_Type uint columnNum
Definition: table_c.h:141
#define DECLARE_CACHED_IMPL(className)
Definition: sharedimpl.h:313
A write-only, forward cursor into a table.
Definition: table.h:142
unsigned long long uint64
Definition: types.h:87
static const char * NAME_TAG
Configuration tag for a Table&#39;s Name.
Definition: table.h:29
Xpace_StoreAccess access
Definition: table_c.h:42
static StatusCallback defaultStatus
Default status function.
Definition: types.h:461
Xpace::Source< uint > Source
read-only cursor into a table, parameterized on column
Definition: table.h:122
uint col
Definition: table_c.h:69
const Xpace_Char16 * name
Sink callbacks for table data.
Definition: table_c.h:141
Copyright (C) 2012 Xpace, LLC.
StoreAccess
Definition: data.h:136
std::function< int64(uint64 val)> StatusCallback
A status callback passed to operations that could be time-consuming.
Definition: types.h:457
uint64 row
Begin a new row, committing this one (if any)
Definition: table_c.h:89
std::unique_ptr< Source, SourceDeleter > SourcePtr
Definition: table.h:130
uint uint64 Xpace_Table_Sink * sink
Definition: table_c.h:340
Xpace project main namespace
Definition: datetime.h:18
Can&#39;t create a Source.
Definition: table.h:198
Can&#39;t open a Table.
Definition: table.h:186

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