rllib  1
Public Member Functions | Private Attributes | List of all members
rlSpreadsheetTable Class Reference

#include <rlspreadsheet.h>

Collaboration diagram for rlSpreadsheetTable:
Collaboration graph
[legend]

Public Member Functions

 rlSpreadsheetTable (char delimitor='\t')
 column = 1...N, row = 1...N More...
 
virtual ~rlSpreadsheetTable ()
 
const char * text (int column, int row)
 
void setText (int column, int row, const char *text)
 
int printf (int column, int row, const char *format,...)
 
void clear ()
 
int read (const char *filename)
 
int write (const char *filename)
 
void setNextTable (rlSpreadsheetTable *next)
 
rlSpreadsheetTablegetNextTable ()
 
rlSpreadsheetRowgetFirstRow ()
 
int exists (int column, int row)
 
void setDelimitor (char delimitor)
 

Private Attributes

char delimitor
 
rlSpreadsheetRowfirstRow
 
rlSpreadsheetTablenextTable
 

Detailed Description

A spreadsheet Table.
The class works with CSV files.

Definition at line 69 of file rlspreadsheet.h.

Constructor & Destructor Documentation

◆ rlSpreadsheetTable()

rlSpreadsheetTable::rlSpreadsheetTable ( char  delimitor = '\t')

column = 1...N, row = 1...N

Definition at line 254 of file rlspreadsheet.cpp.

255 {
256  firstRow = NULL;
257  nextTable = NULL;
258  delimitor = del;
259 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetTable * nextTable
Definition: rlspreadsheet.h:89

◆ ~rlSpreadsheetTable()

rlSpreadsheetTable::~rlSpreadsheetTable ( )
virtual

Definition at line 261 of file rlspreadsheet.cpp.

262 {
263  rlSpreadsheetRow *item,*last;
264  item = firstRow;
265  while(item != NULL)
266  {
267  last = item;
268  item = item->getNextRow();
269  if(item != last) delete last;
270  }
271 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()

Member Function Documentation

◆ clear()

void rlSpreadsheetTable::clear ( )

Definition at line 319 of file rlspreadsheet.cpp.

320 {
321  rlSpreadsheetRow *item;
322 
323  item = firstRow;
324  while(item != NULL)
325  {
326  item->clear();
327  item = item->getNextRow();
328  }
329 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()

◆ exists()

int rlSpreadsheetTable::exists ( int  column,
int  row 
)

Definition at line 406 of file rlspreadsheet.cpp.

407 {
408  rlSpreadsheetRow *item;
409  int r;
410 
411  r = 1;
412  item = firstRow;
413  while(item != NULL)
414  {
415  if(r == row) return item->exists(column);
416  r++;
417  item = item->getNextRow();
418  }
419  return 0;
420 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()
int exists(int column)

◆ getFirstRow()

rlSpreadsheetRow * rlSpreadsheetTable::getFirstRow ( )

Definition at line 396 of file rlspreadsheet.cpp.

397 {
398  return firstRow;
399 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88

◆ getNextTable()

rlSpreadsheetTable * rlSpreadsheetTable::getNextTable ( )

Definition at line 401 of file rlspreadsheet.cpp.

402 {
403  return nextTable;
404 }
rlSpreadsheetTable * nextTable
Definition: rlspreadsheet.h:89

◆ printf()

int rlSpreadsheetTable::printf ( int  column,
int  row,
const char *  format,
  ... 
)

Definition at line 306 of file rlspreadsheet.cpp.

307 {
308  int ret;
309  char buf[rl_PRINTF_LENGTH_SPREADSHEET]; // should be big enough
310 
311  va_list ap;
312  va_start(ap,format);
313  ret = rlvsnprintf(buf, rl_PRINTF_LENGTH_SPREADSHEET - 1, format, ap);
314  va_end(ap);
315  setText(column,row,buf);
316  return ret;
317 }
void setText(int column, int row, const char *text)
#define rl_PRINTF_LENGTH_SPREADSHEET
Definition: rldefine.h:72
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
Definition: rlcutil.cpp:197

◆ read()

int rlSpreadsheetTable::read ( const char *  filename)

Definition at line 331 of file rlspreadsheet.cpp.

332 {
333  FILE *fp;
334  rlSpreadsheetRow *item,*last,*next;
335  unsigned char *line;
336  int r = 1;
337  if(filename == NULL) return -1;
338 
339  // delete old table
340  item = firstRow;
341  while(item != NULL)
342  {
343  last = item;
344  item = item->getNextRow();
345  if(item != last) delete last;
346  }
347 
348  // read new table
349  fp = fopen(filename,"r");
350  if(fp == NULL) return -1;
351  line = new unsigned char[256*256+1];
352  while(fgets((char *) line,256*256,fp) != NULL)
353  {
354  if(r==1)
355  {
356  item = firstRow = new rlSpreadsheetRow;
357  }
358  else
359  {
360  next = new rlSpreadsheetRow;
361  item->setNextRow(next);
362  item = next;
363  }
364  item->readRow(line,delimitor);
365  r++;
366  }
367  delete [] line;
368  fclose(fp);
369  return r - 1; // number of lines that have been read
370 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()
void setNextRow(rlSpreadsheetRow *next)
void readRow(const unsigned char *line, char delimitor='\t')

◆ setDelimitor()

void rlSpreadsheetTable::setDelimitor ( char  delimitor)

Definition at line 422 of file rlspreadsheet.cpp.

423 {
424  delimitor = _delimitor;
425 }

◆ setNextTable()

void rlSpreadsheetTable::setNextTable ( rlSpreadsheetTable next)

Definition at line 391 of file rlspreadsheet.cpp.

392 {
393  nextTable = next;
394 }
rlSpreadsheetTable * nextTable
Definition: rlspreadsheet.h:89

◆ setText()

void rlSpreadsheetTable::setText ( int  column,
int  row,
const char *  text 
)

Definition at line 288 of file rlspreadsheet.cpp.

289 {
290  int r = 1;
291  rlSpreadsheetRow *item,*nextitem;
292 
293  if(row < 1) return;
294  if(firstRow == NULL) firstRow = new rlSpreadsheetRow;
295  item = firstRow;
296  while(1)
297  {
298  if(r == row) { item->setText(column,text); return; }
299  nextitem = item->getNextRow();
300  if(nextitem == NULL) item->setNextRow(new rlSpreadsheetRow);
301  item = item->getNextRow();
302  r++;
303  }
304 }
const char * text(int column, int row)
void setText(int column, const char *text)
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()
void setNextRow(rlSpreadsheetRow *next)

◆ text()

const char * rlSpreadsheetTable::text ( int  column,
int  row 
)

Definition at line 273 of file rlspreadsheet.cpp.

274 {
275  int r = 1;
276  rlSpreadsheetRow *item;
277 
278  item = firstRow;
279  while(item != NULL)
280  {
281  if(r == row) return item->text(column);
282  item = item->getNextRow();
283  r++;
284  }
285  return null_string;
286 }
const char * text(int column)
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()
static const char null_string[]

◆ write()

int rlSpreadsheetTable::write ( const char *  filename)

Definition at line 372 of file rlspreadsheet.cpp.

373 {
374  rlSpreadsheetRow *item;
375  FILE *fp;
376  if(filename == NULL) return -1;
377  fp = fopen(filename,"w");
378  if(fp == NULL) return -1;
379 
380  item = firstRow;
381  while(item != NULL)
382  {
383  item->writeRow((void *) fp, delimitor);
384  item = item->getNextRow();
385  }
386 
387  fclose(fp);
388  return 0;
389 }
rlSpreadsheetRow * firstRow
Definition: rlspreadsheet.h:88
rlSpreadsheetRow * getNextRow()
void writeRow(void *fp, char delimitor='\t')

Member Data Documentation

◆ delimitor

char rlSpreadsheetTable::delimitor
private

Definition at line 87 of file rlspreadsheet.h.

◆ firstRow

rlSpreadsheetRow* rlSpreadsheetTable::firstRow
private

Definition at line 88 of file rlspreadsheet.h.

◆ nextTable

rlSpreadsheetTable* rlSpreadsheetTable::nextTable
private

Definition at line 89 of file rlspreadsheet.h.


The documentation for this class was generated from the following files: