This file is indexed.

/usr/include/Bpp/Numeric/DataTable.h is in libbpp-core-dev 2.1.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//
// File: DataTable.h
// Created by: Julien Dutheil
// Created on: Aug 2005
//

/*
Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)

This software is a computer program whose purpose is to provide classes
for numerical calculus.

This software is governed by the CeCILL  license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*/

#ifndef _DataTable_H_
#define _DataTable_H_

#include "VectorTools.h"
#include "DataTableExceptions.h"
#include "../Exceptions.h"
#include "../Text/TextTools.h"
#include "../Clonable.h"

// From the STL:
#include <string>
#include<vector>
#include <map>

namespace bpp
{

/**
 * @brief This class corresponds to a 'dataset', <i>i.e.</i> a table with data by rows
 * and variable by columns.
 *
 * Data are stored as string objects, by column.
 * A DataTable object is hence similar to a ColMatrix<string>.object.
 * (NB: actually, ColMatrix does not exist yet...)
 */
class DataTable:
  public Clonable
{
  
  protected:
    size_t nRow_, nCol_;
    std::vector< std::vector<std::string> > data_;
    std::vector<std::string>* rowNames_;
    std::vector<std::string>* colNames_;

  public:
    
    /**
     * @brief Build a new void DataTable object with nRow rows and nCol columns.
     *
     * @param nRow The number of rows of the DataTable.
     * @param nCol The number of columns of the DataTable.
     */
    DataTable(size_t nRow, size_t nCol);
    
    /**
     * @brief Build a new void DataTable object with nCol columns.
     *
     * @param nCol The number of columns of the DataTable.
     */
    DataTable(size_t nCol);

    /**
     * @brief Build a new void DataTable object with named columns.
     *
     * @param colNames The names of the columns of the DataTable.
     * @throw DuplicatedTableColumnNameException If colnames contains identical names.
     */
    DataTable(const std::vector<std::string>& colNames) throw (DuplicatedTableColumnNameException);

    DataTable(const DataTable& table);

    DataTable& operator=(const DataTable& table);

    DataTable* clone() const { return new DataTable(*this); }

    virtual ~DataTable();

  public:

    /**
     * @return The element at a given position.
     * @param rowIndex Row number.
     * @param colIndex Column number.
     * @throw IndexOutOfBoundsException If one of the index is greater or equal to the corresponding number of columns/rows. 
     */
    std::string& operator()(size_t rowIndex, size_t colIndex) throw (IndexOutOfBoundsException);
    
    /**
     * @return The element at a given position.
     * @param rowIndex Row number.
     * @param colIndex Column number.
     * @throw IndexOutOfBoundsException If one of the index is greater or equal to the corresponding number of columns/rows. 
     */
    const std::string& operator()(size_t rowIndex, size_t colIndex) const throw (IndexOutOfBoundsException);
    
    /**
     * @return The element at a given position.
     * @param rowName Row name.
     * @param colName Column name.
     * @throw NoTableRowNamesException If the table does not have names associated to rows. 
     * @throw NoTableColumnNamesException If the table does not have names associated to columns. 
     * @throw TableNameNotFoundException If one of rowName or colName do not match existing names. 
     */
    std::string& operator()(const std::string& rowName, const std::string& colName)
            throw (NoTableRowNamesException, NoTableColumnNamesException, TableNameNotFoundException);
    
    /**
     * @return The element at a given position.
     * @param rowName Row name.
     * @param colName Column name.
     * @throw NoTableRowNamesException If the table does not have names associated to rows. 
     * @throw NoTableColumnNamesException If the table does not have names associated to columns. 
     * @throw TableNameNotFoundException If one of rowName or colName do not match existing names. 
     */
    const std::string& operator()(const std::string& rowName, const std::string& colName) const
            throw (NoTableRowNamesException, NoTableColumnNamesException, TableNameNotFoundException);
    
    /**
     * @return The element at a given position.
     * @param rowName Row name.
     * @param colIndex Column number.
     * @throw NoTableRowNamesException If the table does not have names associated to rows. 
     * @throw IndexOutOfBoundsException If the index is greater or equal to the number of columns. 
     * @throw TableNameNotFoundException If rowName do not match existing names. 
     */
    std::string& operator()(const std::string& rowName, size_t colIndex)
            throw (NoTableRowNamesException, TableNameNotFoundException, IndexOutOfBoundsException);
    
    /**
     * @return The element at a given position.
     * @param rowName Row name.
     * @param colIndex Column number.
     * @throw NoTableRowNamesException If the table does not have names associated to rows. 
     * @throw IndexOutOfBoundsException If the index is greater or equal to the number of columns. 
     * @throw TableNameNotFoundException If rowName do not match existing names. 
     */
    const std::string& operator()(const std::string& rowName, size_t colIndex) const
            throw (NoTableRowNamesException, TableNameNotFoundException, IndexOutOfBoundsException);

    /**
     * @return The element at a given position.
     * @param rowIndex Row number.
     * @param colName Column name.
     * @throw IndexOutOfBoundsException If the index is greater or equal to the number of rows. 
     * @throw NoTableColumnNamesException If the table does not have names associated to columns. 
     * @throw TableNameNotFoundException If colName do not match existing names. 
     */
    std::string& operator()(size_t rowIndex, const std::string& colName)
            throw (IndexOutOfBoundsException, NoTableColumnNamesException, TableNameNotFoundException);
    
    /**
     * @return The element at a given position.
     * @param rowIndex Row number.
     * @param colName Column name.
     * @throw IndexOutOfBoundsException If the index is greater or equal to the number of rows. 
     * @throw NoTableColumnNamesException If the table does not have names associated to columns. 
     * @throw TableNameNotFoundException If colName do not match existing names. 
     */
    const std::string& operator()(size_t rowIndex, const std::string& colName) const
            throw (IndexOutOfBoundsException, NoTableColumnNamesException, TableNameNotFoundException);
    
    /**
     * @name Work on columns.
     *
     * @{
     */

    /**
     * @return The number of columns in this table.
     */
    size_t getNumberOfColumns() const { return nCol_; }

    /**
     * @brief Set the column names of this table.
     * 
     * @param colNames The row names.
     * @throw DimensionException If the number of names do not match the number of columns in the table.
     * @throw DuplicatedTableColumnNameException If names are not unique.
     */
    void setColumnNames(const std::vector<std::string>& colNames) throw (DimensionException, DuplicatedTableColumnNameException);
    /**
     * @brief Get the column names of this table.
     * 
     * @return The column names of this table.
     * @throw NoTableColumnNamesException If no column names are associated to this table.
     */
    std::vector<std::string> getColumnNames() const throw (NoTableColumnNamesException);
    /**
     * @brief Get a given column name.
     * 
     * @param index The index of the column.
     * @return The column name associated to the given column.
     * @throw NoTableColumnNamesException If no column names are associated to this table.
     * @throw IndexOutOfBoundsException If index is >= number of columns.
     */
    std::string getColumnName(size_t index) const throw (NoTableColumnNamesException, IndexOutOfBoundsException);
    
    /**
     * @return true If column names are associated to this table.
     */
    bool hasColumnNames() const { return colNames_!= 0; }

    /**
     * @return The values in the given column.
     * @param index The index of the column.
     * @throw IndexOutOfBoundsException If index is >= number of columns.
     */
    std::vector<std::string>& getColumn(size_t index) throw (IndexOutOfBoundsException);
    /**
     * @return The values in the given column.
     * @param index The index of the column.
     * @throw IndexOutOfBoundsException If index is >= number of columns.
     */
    const std::vector<std::string>& getColumn(size_t index) const throw (IndexOutOfBoundsException);
    
    /**
     * @return The values in the given column.
     * @param colName The name of the column.
     * @throw NoTableColumnNamesException If no column names are associated to this table.
     * @throw TableColumnNameNotFoundException If colName do not match existing column names. 
     */
    std::vector<std::string>& getColumn(const std::string& colName) throw (NoTableColumnNamesException, TableColumnNameNotFoundException);
    /**
     * @return The values in the given column.
     * @param colName The name of the column.
     * @throw NoTableColumnNamesException If no column names are associated to this table.
     * @throw TableColumnNameNotFoundException If colName do not match existing column names. 
     */
    const std::vector<std::string>& getColumn(const std::string& colName) const throw (NoTableColumnNamesException, TableColumnNameNotFoundException);

    /**
     * @brief Tell is a given column exists.
     *
     * @param colName The name of the column to look for.
     * @return true if the column was found, false if not or if there are no column names.
     */
    bool hasColumn(const std::string& colName) const;

    /**
     * @brief Delete the given column.
     * 
     * @param index The index of the column.
     * @throw IndexOutOfBoundsException If index is >= number of columns.
     */
    void deleteColumn(size_t index) throw (IndexOutOfBoundsException);
    
    /**
     * @brief Delete the given column.
     * 
     * @param colName The name of the column.
     * @throw NoTableColumnNamesException If no column names are associated to this table.
     * @throw TableColumnNameNotFoundException If colName do not match existing column names. 
     */
    void deleteColumn(const std::string& colName) throw (NoTableColumnNamesException, TableColumnNameNotFoundException);
  
    /**
     * @brief Add a new column.
     *
     * @param newColumn The new column values.
     * @throw DimensionException If the number of values does not match the number of rows.
     * @throw TableColumnNamesException If the table has row names.
     */
    void addColumn(const std::vector<std::string>& newColumn) throw (DimensionException, TableColumnNamesException);
    /**
     * @brief Add a new column.
     *
     * @param colName   The name of the column.
     * @param newColumn The new column values.
     * @throw DimensionException If the number of values does not match the number of rows.
     * @throw NoTableColumnNamesException If the table does not have row names.
     * @throw DuplicatedTableColumnNameException If colName is already used.
     */
    void addColumn(const std::string& colName, const std::vector<std::string>& newColumn) throw (DimensionException, NoTableColumnNamesException, DuplicatedTableColumnNameException);
    /** @} */
    
    /**
     * @name Work on rows.
     *
     * @{
     */
    
    /**
     * @return The number of rows in this table.
     */
    size_t getNumberOfRows() const { return nRow_; }

    /**
     * @brief Set the row names of this table.
     * 
     * @param rowNames The row names.
     * @throw DimensionException If the number of names do not match the number of rows in the table.
     * @throw DuplicatedTableRowNameException If names are not unique.
     */
    void setRowNames(const std::vector<std::string>& rowNames) throw (DimensionException, DuplicatedTableRowNameException);

    /**
     * @brief Get the row names of this table.
     * 
     * @return The row names of this table.
     * @throw NoTableRowNamesException If no row names are associated to this table.
     */
    std::vector<std::string> getRowNames() const throw (NoTableRowNamesException);

    /**
     * @brief Tell is a given row exists.
     *
     * @param rowName The name of the row to look for.
     * @return true if the row was found, false if not or if there are no row names.
     */
    bool hasRow(const std::string& rowName) const;

    /**
     * @brief Get a given row name.
     * 
     * @param index The index of the row.
     * @return The row name associated to the given row.
     * @throw NoTableRowNamesException If no row names are associated to this table.
     * @throw IndexOutOfBoundsException If index is >= number of rows.
     */
    std::string getRowName(size_t index) const throw (NoTableRowNamesException, IndexOutOfBoundsException);

    /**
     * @return true If row names are associated to this table.
     */
    bool hasRowNames() const { return rowNames_!= 0; }

    /**
     * @return A vector which contains a copy  in the given row.
     * @param index The index of the row.
     * @throw IndexOutOfBoundsException If index is >= number of rows.
     */
    std::vector<std::string> getRow(size_t index) const throw (IndexOutOfBoundsException);

    /**
     * @return A vector which contains a copy  in the given row.
     * @param rowName The name of the row.
     * @throw NoTableRowNamesException If no row names are associated to this table.
     * @throw TableRowNameNotFoundException If rowName do not match existing row names.
     */
    std::vector<std::string> getRow(const std::string& rowName) const throw (NoTableRowNamesException, TableRowNameNotFoundException);

    /**
     * @brief Delete the given row.
     * 
     * @param index The index of the row.
     * @throw IndexOutOfBoundsException If index is >= number of row.
     */
    void deleteRow(size_t index) throw (IndexOutOfBoundsException);

    /**
     * @brief Delete the given row.
     * 
     * @param rowName The name of the row.
     * @throw NoTableRowNamesException If no row names are associated to this table.
     * @throw TableRowNameNotFoundException If rowName do not match existing column names. 
     */
    void deleteRow(const std::string& rowName) throw (NoTableRowNamesException, TableRowNameNotFoundException);
    
    /**
     * @brief Add a new row.
     *
     * @param newRow The new row values.
     * @throw DimensionException If the number of values does not match the number of columns.
     * @throw TableRowNamesException If the table has column names.
     */
    void addRow(const std::vector<std::string>& newRow) throw (DimensionException, TableRowNamesException);
    /**
     * @brief Add a new row.
     *
     * @param rowName   The name of the row.
     * @param newRow    The new row values.
     * @throw DimensionException If the number of values does not match the number of columns.
     * @throw NoTableRowNamesException If the table does not have column names.
     * @throw DuplicatedTableRowNameException If rowName is already used.
     */
    void addRow(const std::string& rowName, const std::vector<std::string>& newRow) throw (DimensionException, NoTableRowNamesException, DuplicatedTableRowNameException);
    /** @} */

  public:

    /**
     * @brief Read a table form a stream in CSV-like format.
     *
     * The number of rows is given by the second line in the file.
     * By default, if the first line as one column less than the second one,
     * the first line is taken as column names, and the first column as row names.
     * Otherwise, no column names and no row names are specified, unless
     * explicitely precised by the user.
     * 
     * @param in       The input stream.
     * @param sep      The column delimiter.
     * @param header   Tell if the first line must be used as column names, otherwise use default.
     * @param rowNames Use a column as rowNames. If positive, use the specified column to compute rownames, otherwise use default;
     * @return         A pointer toward a new DataTable object.
     */
    static DataTable* read(std::istream& in, const std::string& sep = "\t", bool header = true, int rowNames = -1)
      throw (DimensionException, IndexOutOfBoundsException, DuplicatedTableRowNameException);

    /**
     * @brief Write a DataTable object to stream in CVS-like format.
     * 
     * @param data         The table to write.
     * @param out          The output stream.
     * @param sep          The column delimiter.
     * @param alignHeaders If true, add a delimiter before the first column header if there is row names.
     */
    static void write(const DataTable& data, std::ostream& out, const std::string& sep = "\t", bool alignHeaders = false);
};

} //end of namespace bpp.

#endif //_DataTable_H_