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

#include <rlspreadsheet.h>

Collaboration diagram for rlSpreadsheetWorkbook:
Collaboration graph
[legend]

Public Member Functions

 rlSpreadsheetWorkbook (char delimitor='\t')
 column = 1...N, row = 1...N, page = 1...N More...
 
virtual ~rlSpreadsheetWorkbook ()
 
const char * text (int column, int row, int page)
 
void setText (int column, int row, int page, const char *text)
 
int printf (int column, int row, int page, const char *format,...)
 
void clear ()
 
int read (const char *filename)
 
int write (const char *filename)
 
int exists (int column, int row, int page)
 
rlSpreadsheetTablegetFirstTable ()
 
void setDelimitor (char delimitor)
 

Private Attributes

char delimitor
 
rlSpreadsheetTablefirstTable
 

Detailed Description

A series of spreadsheet tables.
The class works with CSV files.

Definition at line 96 of file rlspreadsheet.h.

Constructor & Destructor Documentation

◆ rlSpreadsheetWorkbook()

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

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

Definition at line 428 of file rlspreadsheet.cpp.

429 {
430  firstTable = NULL;
431  delimitor = del;
432 }
rlSpreadsheetTable * firstTable

◆ ~rlSpreadsheetWorkbook()

rlSpreadsheetWorkbook::~rlSpreadsheetWorkbook ( )
virtual

Definition at line 434 of file rlspreadsheet.cpp.

435 {
436  rlSpreadsheetTable *item,*last;
437  item = firstTable;
438  while(item != NULL)
439  {
440  last = item;
441  item = item->getNextTable();
442  if(item != last) delete last;
443  }
444 }
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable

Member Function Documentation

◆ clear()

void rlSpreadsheetWorkbook::clear ( )

Definition at line 492 of file rlspreadsheet.cpp.

493 {
494  rlSpreadsheetTable *item;
495 
496  item = firstTable;
497  while(item != NULL)
498  {
499  item->clear();
500  item = item->getNextTable();
501  }
502 }
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable

◆ exists()

int rlSpreadsheetWorkbook::exists ( int  column,
int  row,
int  page 
)

Definition at line 575 of file rlspreadsheet.cpp.

576 {
577  rlSpreadsheetTable *item;
578  int p;
579 
580  p = 1;
581  item = firstTable;
582  while(item != NULL)
583  {
584  if(p == page) return item->exists(column,row);
585  p++;
586  item = item->getNextTable();
587  }
588  return 0;
589 }
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable
int exists(int column, int row)

◆ getFirstTable()

rlSpreadsheetTable * rlSpreadsheetWorkbook::getFirstTable ( )

Definition at line 591 of file rlspreadsheet.cpp.

592 {
593  return firstTable;
594 }
rlSpreadsheetTable * firstTable

◆ printf()

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

Definition at line 479 of file rlspreadsheet.cpp.

480 {
481  int ret;
482  char buf[rl_PRINTF_LENGTH_SPREADSHEET]; // should be big enough
483 
484  va_list ap;
485  va_start(ap,format);
486  ret = rlvsnprintf(buf, rl_PRINTF_LENGTH_SPREADSHEET - 1, format, ap);
487  va_end(ap);
488  setText(column,row,page,buf);
489  return ret;
490 }
#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
void setText(int column, int row, int page, const char *text)

◆ read()

int rlSpreadsheetWorkbook::read ( const char *  filename)

Definition at line 504 of file rlspreadsheet.cpp.

505 {
506  FILE *fp;
507  rlSpreadsheetTable *item,*last,*next;
508  int p = 1;
509  char buf[16],*fname;
510  if(filename == NULL) return -1;
511 
512  // delete old workbook
513  item = firstTable;
514  while(item != NULL)
515  {
516  last = item;
517  item = item->getNextTable();
518  if(item != last) delete last;
519  }
520 
521  // read new workbook
522  fname = new char[strlen(filename)+16];
523  while(1)
524  {
525  strcpy(fname,filename);
526  sprintf(buf,"%d.txt",p);
527  strcat(fname,buf);
528  // test if file exists
529  fp = fopen(fname,"r");
530  if(fp == NULL) break;
531  fclose(fp);
532  if(p==1)
533  {
535  }
536  else
537  {
538  next = new rlSpreadsheetTable(delimitor);
539  item->setNextTable(next);
540  item = next;
541  }
542  if(item->read(fname) < 0) break;
543  p++;
544  }
545 
546  delete [] fname;
547  return 0;
548 }
int read(const char *filename)
void setNextTable(rlSpreadsheetTable *next)
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable

◆ setDelimitor()

void rlSpreadsheetWorkbook::setDelimitor ( char  delimitor)

Definition at line 596 of file rlspreadsheet.cpp.

597 {
598  delimitor = _delimitor;
600  while(table != NULL)
601  {
602  table->setDelimitor(delimitor);
603  table = table->getNextTable();
604  }
605 }
void setDelimitor(char delimitor)
rlSpreadsheetTable * getFirstTable()
rlSpreadsheetTable * getNextTable()

◆ setText()

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

Definition at line 461 of file rlspreadsheet.cpp.

462 {
463  int p = 1;
464  rlSpreadsheetTable *item,*nextitem;
465 
466  if(page < 1) return;
467  if(firstTable == NULL) firstTable = new rlSpreadsheetTable;
468  item = firstTable;
469  while(1)
470  {
471  if(p == page) { item->setText(column, row, text); return; }
472  nextitem = item->getNextTable();
473  if(nextitem == NULL) item->setNextTable(new rlSpreadsheetTable);
474  item = item->getNextTable();
475  p++;
476  }
477 }
void setText(int column, int row, const char *text)
const char * text(int column, int row, int page)
void setNextTable(rlSpreadsheetTable *next)
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable

◆ text()

const char * rlSpreadsheetWorkbook::text ( int  column,
int  row,
int  page 
)

Definition at line 446 of file rlspreadsheet.cpp.

447 {
448  int p = 1;
449  rlSpreadsheetTable *item;
450 
451  item = firstTable;
452  while(item != NULL)
453  {
454  if(p == page) return item->text(column, row);
455  item = item->getNextTable();
456  p++;
457  }
458  return null_string;
459 }
const char * text(int column, int row)
static const char null_string[]
rlSpreadsheetTable * getNextTable()
rlSpreadsheetTable * firstTable

◆ write()

int rlSpreadsheetWorkbook::write ( const char *  filename)

Definition at line 550 of file rlspreadsheet.cpp.

551 {
552  rlSpreadsheetTable *item = NULL;
553  int p = 1;
554  char buf[16],*fname;
555  if(filename == NULL) return -1;
556 
557  // write workbook
558  fname = new char[strlen(filename)+16];
559  while(1)
560  {
561  strcpy(fname,filename);
562  sprintf(buf,"%d.txt",p);
563  strcat(fname,buf);
564  if(p==1) item = firstTable;
565  else item = item->getNextTable();
566  if(item == NULL) break;
567  if(item->write(fname) < 0) break;
568  p++;
569  }
570 
571  delete [] fname;
572  return 0;
573 }
rlSpreadsheetTable * getNextTable()
int write(const char *filename)
rlSpreadsheetTable * firstTable

Member Data Documentation

◆ delimitor

char rlSpreadsheetWorkbook::delimitor
private

Definition at line 112 of file rlspreadsheet.h.

◆ firstTable

rlSpreadsheetTable* rlSpreadsheetWorkbook::firstTable
private

Definition at line 113 of file rlspreadsheet.h.


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