librcsb-core-wrapper  1.000
TTable.h
Go to the documentation of this file.
1 //$$FILE$$
2 //$$VERSION$$
3 //$$DATE$$
4 //$$LICENSE$$
5 
6 
14 #ifndef TTABLE_H
15 #define TTABLE_H
16 
17 
18 #include <string>
19 #include <vector>
20 
21 #include <rcsb/TableError.h>
22 #include <rcsb/Serializer.h>
23 
24 #define TTABLE_COLUMN_DELETE_AS_REMOVE
25 
26 
41 class TTable
42 {
43  public:
57  TTable();
58 
75  TTable(const TTable& inTable);
76 
90  virtual ~TTable();
91 
106  TTable& operator=(const TTable& inTable);
107 
121  void Clear();
122 
136  inline unsigned int GetNumTuples() const;
137 
138  /* \todo Re-use much of the comment of InsertTuple() */
139  unsigned int AddTuple(const std::vector<std::string>& tuple =
140  std::vector<std::string>());
141 
178  void InsertTuple(const unsigned int tupleIndex,
179  const std::vector<std::string>& tuple = std::vector<std::string>());
180 
181  void InsertTuple(const unsigned int tupleIndex,
182  std::vector<std::string>::const_iterator tupleBeg,
183  std::vector<std::string>::const_iterator tupleEnd);
184 
218  void FillTuple(const unsigned int tupleIndex,
219  const std::vector<std::string>& tuple,
220  const unsigned int fromColIndex = 0);
221 
222  void GetTuple(std::vector<std::string>& tuple,
223  const unsigned int tupleIndex,
224  const unsigned int fromColIndex, unsigned int toColIndex);
225 
226  const std::vector<std::string>& GetTuple(const unsigned int tupleIndex);
227 
244  void ClearTuple(const unsigned int tupleIndex);
245 
262  void DeleteTuple(const unsigned int tupleIndex);
263 
275  inline unsigned int GetNumColumns() const;
276 
307  unsigned int AddColumn(const std::vector<std::string>& col =
308  std::vector<std::string>());
309 
352  unsigned int InsertColumn(const unsigned int atColIndex,
353  const std::vector<std::string>& col = std::vector<std::string>());
354 
355  void InsertColumn(const unsigned int atColIndex,
356  std::vector<std::string>::const_iterator colBeg,
357  std::vector<std::string>::const_iterator colEnd);
358 
383  void FillColumn(const unsigned int colIndex,
384  const std::vector<std::string>& col,
385  const unsigned int fromTupleIndex = 0);
386 
387  void FillColumn(const unsigned int colIndex,
388  std::vector<std::string>::const_iterator colBeg,
389  std::vector<std::string>::const_iterator colEnd,
390  const unsigned int fromTupleIndex = 0);
391 
431  void GetColumn(std::vector<std::string>& col, const unsigned int colIndex,
432  const unsigned int fromTupleIndex, unsigned int toTupleIndex);
433 
449  void ClearColumn(const unsigned int colIndex);
450 
468  void DeleteColumn(const unsigned int colIndex);
469 
491  std::string& operator()(const unsigned int tupleIndex,
492  const unsigned int colIndex);
493 
515  const std::string& operator()(const unsigned int tupleIndex,
516  const unsigned int colIndex) const;
517 
518  int Write(Serializer* ser, unsigned int& size);
519  int Read(UInt32 index, Serializer* ser);
520 
521  private:
522  unsigned int _numCols;
523 
524  std::vector<std::vector<std::string>*> _tuples;
525 
526  inline unsigned int IntColIndex(const unsigned int colIndex) const;
527 
528 #ifndef TTABLE_COLUMN_DELETE_AS_REMOVE
529  unsigned int _numDelCols;
530  std::vector<unsigned int> _delColMap;
531 
532  void EnlargeColMap(const unsigned int numCols);
533  void ReduceColMap(const unsigned int numCols);
534  void MarkColDeleted(const unsigned int colIndex);
535  void UnMarkColDeleted(const unsigned int colIndex);
536 #endif
537 
538 };
539 
540 
541 std::ostream& operator<<(std::ostream& out, const TTable& sTable);
542 
543 
544 inline unsigned int TTable::GetNumTuples() const
545 {
546  return(_tuples.size());
547 }
548 
549 
550 inline unsigned int TTable::GetNumColumns() const
551 {
552 #ifndef TTABLE_COLUMN_DELETE_AS_REMOVE
553  return(_numCols - _numDelCols);
554 #else
555  return(_numCols);
556 #endif
557 }
558 
559 inline unsigned int TTable::IntColIndex(const unsigned int colIndex) const
560 {
561 
562  // Returns the TTable internal column index
563 #ifndef TTABLE_COLUMN_DELETE_AS_REMOVE
564  return(_delColMap[colIndex]);
565 #else
566  return(colIndex);
567 #endif
568 }
569 
570 #endif // TTABLE_H