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

#include <rlspreadsheet.h>

Collaboration diagram for rlSpreadsheetRow:
Collaboration graph
[legend]

Public Member Functions

 rlSpreadsheetRow ()
 column = 1...N More...
 
virtual ~rlSpreadsheetRow ()
 
const char * text (int column)
 
void setText (int column, const char *text)
 
int printf (int column, const char *format,...)
 
void clear ()
 
void setNextRow (rlSpreadsheetRow *next)
 
rlSpreadsheetRowgetNextRow ()
 
rlSpreadsheetCellgetFirstCell ()
 
void readRow (const unsigned char *line, char delimitor='\t')
 
void writeRow (void *fp, char delimitor='\t')
 
int exists (int column)
 

Private Attributes

rlSpreadsheetCellfirstCell
 
rlSpreadsheetRownextRow
 

Detailed Description

A row within a spreadsheet.

Definition at line 44 of file rlspreadsheet.h.

Constructor & Destructor Documentation

◆ rlSpreadsheetRow()

rlSpreadsheetRow::rlSpreadsheetRow ( )

column = 1...N

Definition at line 97 of file rlspreadsheet.cpp.

98 {
99  firstCell = NULL;
100  nextRow = NULL;
101 }
rlSpreadsheetRow * nextRow
Definition: rlspreadsheet.h:62
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61

◆ ~rlSpreadsheetRow()

rlSpreadsheetRow::~rlSpreadsheetRow ( )
virtual

Definition at line 103 of file rlspreadsheet.cpp.

104 {
105  rlSpreadsheetCell *item,*last;
106  item = firstCell;
107  while(item != NULL)
108  {
109  last = item;
110  item = item->getNextCell();
111  if(item != last) delete last;
112  }
113 }
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()

Member Function Documentation

◆ clear()

void rlSpreadsheetRow::clear ( )

Definition at line 161 of file rlspreadsheet.cpp.

162 {
163  rlSpreadsheetCell *item;
164 
165  item = firstCell;
166  while(item != NULL)
167  {
168  item->clear();
169  item = item->getNextCell();
170  }
171 }
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()

◆ exists()

int rlSpreadsheetRow::exists ( int  column)

Definition at line 237 of file rlspreadsheet.cpp.

238 {
239  rlSpreadsheetCell *item;
240  int c;
241 
242  c = 1;
243  item = firstCell;
244  while(item != NULL)
245  {
246  if(c == column) return 1;
247  c++;
248  item = item->getNextCell();
249  }
250  return 0;
251 }
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()

◆ getFirstCell()

rlSpreadsheetCell * rlSpreadsheetRow::getFirstCell ( )

Definition at line 183 of file rlspreadsheet.cpp.

184 {
185  return firstCell;
186 }
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61

◆ getNextRow()

rlSpreadsheetRow * rlSpreadsheetRow::getNextRow ( )

Definition at line 178 of file rlspreadsheet.cpp.

179 {
180  return nextRow;
181 }
rlSpreadsheetRow * nextRow
Definition: rlspreadsheet.h:62

◆ printf()

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

Definition at line 148 of file rlspreadsheet.cpp.

149 {
150  int ret;
151  char buf[rl_PRINTF_LENGTH_SPREADSHEET]; // should be big enough
152 
153  va_list ap;
154  va_start(ap,format);
155  ret = rlvsnprintf(buf, rl_PRINTF_LENGTH_SPREADSHEET - 1, format, ap);
156  va_end(ap);
157  setText(column,buf);
158  return ret;
159 }
void setText(int column, 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

◆ readRow()

void rlSpreadsheetRow::readRow ( const unsigned char *  line,
char  delimitor = '\t' 
)

Definition at line 188 of file rlspreadsheet.cpp.

189 {
190  int i,tab1,tab2,col;
191  unsigned char *celltext;
192 
193  clear();
194 
195  tab1 = tab2 = -1;
196  col = 1;
197  i = 0;
198  while(line[i] != '\0')
199  {
200  if(line[i] == delimitor || line[i] == '\n' || line[i] == 0x0d) // normally delimitor='\t'
201  {
202  tab1 = tab2;
203  tab2 = i;
204  celltext = new unsigned char[tab2-tab1+1];
205  if(tab2 > tab1)
206  {
207  strncpy((char *) celltext,(const char *) &line[tab1+1],tab2-tab1);
208  celltext[tab2-tab1-1] = '\0';
209  }
210  else
211  {
212  celltext[0] = '\0';
213  }
214  setText(col++, (char *) celltext);
215  delete [] celltext;
216  }
217  i++;
218  }
219 
220  return;
221 }
void setText(int column, const char *text)

◆ setNextRow()

void rlSpreadsheetRow::setNextRow ( rlSpreadsheetRow next)

Definition at line 173 of file rlspreadsheet.cpp.

174 {
175  nextRow = next;
176 }
rlSpreadsheetRow * nextRow
Definition: rlspreadsheet.h:62

◆ setText()

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

Definition at line 130 of file rlspreadsheet.cpp.

131 {
132  int c = 1;
133  rlSpreadsheetCell *item;
134 
135  if(column < 1) return;
136  if(firstCell == NULL) firstCell = new rlSpreadsheetCell;
137 
138  item = firstCell;
139  while(1)
140  {
141  if(c == column) { item->setText(text); return; }
142  if(item->getNextCell() == NULL) item->setNextCell(new rlSpreadsheetCell);
143  item = item->getNextCell();
144  c++;
145  }
146 }
const char * text(int column)
void setNextCell(rlSpreadsheetCell *next)
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()
void setText(const char *text)

◆ text()

const char * rlSpreadsheetRow::text ( int  column)

Definition at line 115 of file rlspreadsheet.cpp.

116 {
117  int c = 1;
118  rlSpreadsheetCell *item;
119 
120  item = firstCell;
121  while(item != NULL)
122  {
123  if(c == column) return item->text();
124  item = item->getNextCell();
125  c++;
126  }
127  return null_string;
128 }
const char * text()
static const char null_string[]
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()

◆ writeRow()

void rlSpreadsheetRow::writeRow ( void *  fp,
char  delimitor = '\t' 
)

Definition at line 223 of file rlspreadsheet.cpp.

224 {
225  rlSpreadsheetCell *cell;
226  if(fp == NULL) return;
227  cell = firstCell;
228  while(cell != NULL)
229  {
230  fprintf((FILE *) fp,"%s",cell->text());
231  cell = cell->getNextCell();
232  if(cell != NULL) fprintf((FILE *) fp, "%c", delimitor);
233  }
234  fprintf((FILE *) fp,"\n");
235 }
const char * text()
rlSpreadsheetCell * firstCell
Definition: rlspreadsheet.h:61
rlSpreadsheetCell * getNextCell()

Member Data Documentation

◆ firstCell

rlSpreadsheetCell* rlSpreadsheetRow::firstCell
private

Definition at line 61 of file rlspreadsheet.h.

◆ nextRow

rlSpreadsheetRow* rlSpreadsheetRow::nextRow
private

Definition at line 62 of file rlspreadsheet.h.


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