MCS  0.3.3-alpha7
Record.cc
1 // ----------------------------------------------------------------------^
2 // Copyright (C) 2004, 2005, 2006, 2007, 2008 Giorgio Calderone
3 // (mailto: <gcalderone@ifc.inaf.it>)
4 //
5 // This file is part of MCS.
6 //
7 // MCS is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // MCS is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with MCS; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // ----------------------------------------------------------------------$
22 #include "mcs.hh"
23 using namespace mcs;
24 
25 
26 
27 //--------------------------------------------------------------------
29 {
30  buf = NULL;
31  extbuffer = false;
32  free();
33 
34  this->freebuffer = freeBuffer;
35 }
36 
37 
38 mcs::Buffer::Buffer(void* extbuf, unsigned int size,
39  enum BufferFreeOnDestroy freeBuffer)
40 {
41  buf = NULL;
42  extbuffer = false;
43  free();
44 
45  buf = (char*) extbuf;
46  bufsize = size;
47  this->freebuffer = freeBuffer;
48  extbuffer = true;
49 }
50 
51 
52 void mcs::Buffer::set(void* extbuf, unsigned int size,
53  enum BufferFreeOnDestroy freeBuffer)
54 {
55  free();
56 
57  buf = (char*) extbuf;
58  bufsize = size;
59  this->freebuffer = freeBuffer;
60  extbuffer = true;
61 }
62 
63 
65 { free(); }
66 
67 
69 {
70  if ((freebuffer == AUTO_FREE) && buf)
71  std::free(buf);
72 
73  bufsize = 0;
74  select = false;
75  wstart = 0;
76  wlen = 0;
77 }
78 
79 
80 
81 void mcs::Buffer::resize(unsigned int size)
82 {
83  if (extbuffer)
84  if (bufsize < size)
85  throw MCS_FATAL(MSG_NOT_ENOUGH_SPACE, size, bufsize);
86 
87  select = false;
88  if (bufsize == 0) {
89  buf = (char*) malloc(size);
90  bufsize = size;
91  }
92  else if (bufsize < size) {
93  buf = (char*) realloc(buf, size);
94  bufsize = size;
95  }
96 }
97 
98 
99 
100 
101 Buffer& mcs::Buffer::operator()(unsigned int len)
102 {
103  wstart = -1;
104  wlen = len;
105  select = true;
106  return *this;
107 }
108 
109 Buffer& mcs::Buffer::operator()(unsigned int start, unsigned int len)
110 {
111  wstart = start;
112  wlen = len;
113  select = true;
114  return *this;
115 }
116 
117 
118 Buffer& mcs::Buffer::operator<<(const void* extbuf)
119 {
120  if (select) {
121  if (wstart == (unsigned int) -1) { //Append to the end of the buffer
122  unsigned int tt = bufsize;
123  resize(bufsize + wlen);
124  char* p = buf + tt;
125  memcpy(p, extbuf, wlen);
126  }
127  else { //Write in the selected window
128  resize(wstart + wlen);
129  memcpy(buf + wstart, extbuf, wlen);
130  }
131  select = false;
132  }
133  else
134  throw MCS_ERROR( MSG_NO_WINDOWS_SELECTED );
135 
136  return *this;
137 }
138 
139 
140 Buffer& mcs::Buffer::operator<<(istream& stream)
141 {
142  if (select) {
143  if (wstart == (unsigned int) -1)
144  wstart = 0;
145 
146  stream.read(buf + wstart, wlen);
147  select = false;
148  }
149  else {
150  char tmp[2048];
151  while (! stream.eof()) {
152  stream.read(tmp, 2048);
153  int n = stream.gcount(); //Bytes read
154  (*this)(n) << tmp; //Fill the buffer
155  }
156  }
157 
158  return *this;
159 }
160 
161 
162 
163 
164 
166 {
167  if (select) {
168  if (wstart == (unsigned int) -1)
169  wstart = 0;
170 
171  memcpy(extbuf, buf + wstart, wlen);
172  select = false;
173  }
174  else {
175  memcpy(extbuf, buf, bufsize);
176  }
177 
178  return *this;
179 }
180 
181 
182 Buffer& mcs::Buffer::operator>>(ostream& stream)
183 {
184  if (select) {
185  if (wstart == (unsigned int) -1)
186  wstart = 0;
187 
188  stream.write(buf + wstart, wlen);
189  select = false;
190  }
191  else {
192  stream.write(buf, bufsize);
193  }
194 
195  return *this;
196 }
197 
198 
199 char* mcs::Buffer::operator[](unsigned int pos)
200 {
201  if (pos > bufsize-1)
202  throw MCS_ERROR( MSG_INVALID_POSITION, pos );
203 
204  return buf + pos;
205 }
206 
207 
208 unsigned int mcs::Buffer::size()
209 {
210  select = false;
211  return bufsize;
212 }
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 //--------------------------------------------------------------------
227 mcs::Record::Record(bool synchro) :
228  Serializable(MCS_SERIAL_BUFFER), Synchro(), array(false), lmap(false)
229 {
230  synchronize(synchro);
231 }
232 
233 
235 {}
236 
237 
238 mcs::Record::Record(void* llbuf, bool synchro) :
239  Serializable(MCS_SERIAL_BUFFER), Synchro(), array(false), lmap(false)
240 {
241  int i;
242  char* lbuf = (char*) llbuf;
243  unsigned short int count;
244 
245  synchronize(synchro);
246 
247  memcpy(&count, lbuf, sizeof(unsigned short int));
248  lbuf += sizeof(unsigned short int);
249 
250  for (i=0; i<count; i++) {
251  Data d(lbuf);
252  addField(d);
253  lbuf += d.objSize();
254  }
255 }
256 
257 
258 
260  Serializable(MCS_SERIAL_BUFFER), Synchro(), array(false), lmap(false)
261 {
262  for (int i=0; i<from.count(); i++)
263  addField(from[i]);
264 
265  setFieldMap(from);
266 }
267 
268 
270 {
271  clear();
272  for (int i=0; i<from.count(); i++)
273  addField(from[i]);
274 
275  setFieldMap(from);
276  return *this;
277 }
278 
279 
280 
281 unsigned int mcs::Record::objSize()
282 {
283  unsigned int size = 0;
284  int i;
285 
286  size += sizeof(unsigned short int); //array.count()
287 
288  for (i=0; i<count(); i++) {
289  size += array[i].objSize(); //Data objects
290  }
291 
292  return size;
293 }
294 
295 
296 
297 
298 
299 bool mcs::Record::serialize_buffer(char*& buf, unsigned int& size)
300 {
301  unsigned short int lcount = count(), i;
302  unsigned int chunk;
303  Buffer abuf(DONT_FREE); //*
304 
305  abuf(sizeof(lcount)) << &lcount;
306  for (i=0; i< lcount; i++) {
307  void* tmp = array[i].getEntireBuffer(chunk);
308  abuf(chunk) << tmp;
309  free(tmp);
310  }
311 
312  size = abuf.size();
313  buf = abuf[0];
314  return true; //* = will be freed when not needed anymore
315 }
316 
317 
318 
319 
320 //unsigned int mcs::Record::prepareBuffer(void** lbuf, unsigned int bufsize)
321 //{
322 // unsigned int size = objSize();
323 // int i;
324 //
325 // MCS_CRITICAL_SECTION_BEGIN;
326 //
327 // if (*lbuf == NULL) //Allocate the buffer
328 // *lbuf = malloc(size);
329 // else
330 // if (bufsize < size)
331 // throw MCS_ERROR(MSG_NOT_ENOUGH_SPACE, bufsize, size);
332 //
333 // void* p = *lbuf;
334 // unsigned short int lcount = count();
335 // p = my_mempcpy(p, &lcount, sizeof(unsigned short int));
336 //
337 // unsigned int left = size - (((char*) p) - ((char*) *lbuf));
338 // for (i=0; i<lcount; i++) {
339 // unsigned int s = array[i].prepareBuffer(&p, left);
340 // (char*) p += s;
341 // left -= s;
342 // }
343 //
344 // MCS_CRITICAL_SECTION_END;
345 // return size;
346 //}
347 
348 
349 
350 void mcs::Record::clear()
351 {
353  array.clear();
354  lmap.clear();
356 }
357 
358 
360 {
361  return array.count();
362 }
363 
365 {
367  int i = array.count(); lmap.push(i);
368  array.push(d);
370 }
371 
373 {
375  int i = array.count(); lmap.push(i);
376  array.push(d);
378 }
379 
380 void mcs::Record::addField(string v, char tag)
381 {
382  Data d(v, tag);
383  addField(d);
384 }
385 
386 void mcs::Record::addField(int v, char tag)
387 {
388  Data d(v, tag);
389  addField(d);
390 }
391 
392 void mcs::Record::addField(long long int v, char tag)
393 {
394  Data d(v, tag);
395  addField(d);
396 }
397 
398 void mcs::Record::addField(double v, char tag)
399 {
400  Data d(v, tag);
401  addField(d);
402 }
403 
404 
405 Data mcs::Record::pop(int x)
406 {
408 
409  for (int i=x; i<lmap.count(); i++)
410  lmap[i] = lmap[i] - 1;
411  lmap.pop(x);
412  Data d = array.pop(x);
413 
414  MCS_CRITICAL_SECTION_END_RETURN(d);
415 }
416 
417 
418 
420 {
422 
423  Data d = array.peek( posWhoseNameIs(name) );
424 
425  MCS_CRITICAL_SECTION_END_RETURN(d);
426 }
427 
428 
429 Data mcs::Record::field(int pos)
430 {
432 
433  Data d = array.peek( lmap[ pos ] );
434 
435  MCS_CRITICAL_SECTION_END_RETURN(d);
436 }
437 
438 
440 {
441  int pos = posWhoseNameIs(name);
442  return array[ pos ];
443 }
444 
445 
447 {
448  pos = lmap[ pos ];
449  return array[ pos ];
450 }
451 
452 
453 
454 
455 
456 
457 int mcs::Record::posWhoseNameIs(string name, enum ThrowExceptions throwexc)
458 {
459  int i;
460  bool found = false;
461 
462  for (i=0; i<count(); i++)
463  if (array[i].name() == name) {
464  found = true;
465  break;
466  }
467 
468  if (found)
469  return i;
470  else
471  if (throwexc)
472  throw MCS_ERROR(MSG_MISSING_FIELD, name.csz);
473  else
474  return -1;
475 }
476 
477 
478 
479 
481 {
482  unsigned int ui;
483  s = trim(s);
484  smap = s;
485 
486  if (s.empty()) {
487  for (ui=0; ui< (unsigned int) array.count(); ui++)
488  lmap[ui] = ui;
489  }
490  else {
491  s += " ";
492  vector<string> vmap = split(s);
493 
494  for (ui=0; ui<vmap.size(); ui++)
495  lmap[ui] = posWhoseNameIs(vmap[ui]);
496  }
497 }
498 
499 
501 {
502  int i;
503  for (i=0; i<lmap.count(); i++)
504  lmap[i] = rec.lmap[i];
505 }
506 
507 
509 {
510  for (int i=0; i<count(); i++)
511  operator[](i).emptyName();
512 }
513 
514 
515 
517 {
518  for (int i=0; i<count(); i++)
519  operator[](i).setNull();
520 }
521 
522 
523 
524 string mcs::Record::asString(string sep)
525 {
526  string ret;
527 
528  for (int i=0; i<count(); i++) {
529  ret += field(i).sval();
530 
531  if (i < count()-1)
532  ret += sep;
533  }
534 
535  return ret;
536 }
537 
538 string mcs::Record::asStringNames(string sep)
539 {
540  string ret;
541 
542  for (int i=0; i<count(); i++) {
543  ret += field(i).name();
544 
545  if (i < count()-1)
546  ret += sep;
547  }
548 
549  return ret;
550 }
551 
552 
553 string mcs::Record::asStringTypes(string sep)
554 {
555  string ret;
556 
557  for (int i=0; i<count(); i++) {
558  ret += Types2Str(field(i).type(), field(i).isUnsigned());
559 
560  if (i < count()-1)
561  ret += sep;
562  }
563 
564  return ret;
565 }
566 
567 
568 
569 
570 
571 
572 
573 
574 
575 
576 //--------------------------------------------------------
578  lmetarec(false), rs(false)
579 {
580  clear();
582 }
583 
584 
586  clear();
587 }
588 
589 
591 {
592  if (lusemetarec)
594  else
595  throw; //ERROR
596 }
597 
598 
599 
600 
602 {
603  Record* rec = new Record(false);
604 
605  if (lusemetarec) {
606  for (int i=0; i<lmetarec.count(); i++) {
607  rec->addField( lmetarec[i] );
608  (*rec)[i].setNull();
609  (*rec)[i].emptyName();
610  }
611  }
612 
613  return rec;
614 }
615 
616 
617 void mcs::RecordSet::clear()
618 {
619  lid = 0;
620  lknow_nrows = false;
621  laccum = false;
622  lrandom = false;
623  lnrows = 0;
624 
625  //Because the meta record will be filled before calling init()
626  lusemetarec = true;
627 
628  leof = true;
629  lpos = 0;
630  current = 0;
631 
632  lmetarec.clear();
633  rs.clear();
634 }
635 
636 
637 
638 void mcs::RecordSet::init(unsigned char code, unsigned int nrows,
639  Record* meta, short int id)
640 {
641  clear();
642 
643  lid = id;
644 
645  this->code = code;
647  laccum = code & MCS_RS_ACCUM;
648  lrandom = code & MCS_RS_RANDOM;
650  linsert = code & MCS_RS_INSERT;
651  lfetch = ! linsert;
652 
653  lnrows = nrows;
654 
655  if (meta)
656  lmetarec = *meta;
657 
658  if (laccum) {
659  lrandom = true;
660  lknow_nrows = true;
661  }
662 
663  if (linsert) {
664  laccum = true; //We always have all records
665  lrandom = true;
666  lknow_nrows = true;
667  lnrows = 0;
668  }
669 }
670 
671 
672 
674  if (lfetch)
675  throw MCS_ERROR( MSG_INSERT_NOT_ALLOWED );
676 
677  rs.push(rec);
678  lnrows++;
679  leof = false;
680 }
681 
682 
684  if (lfetch)
685  throw MCS_ERROR( MSG_INSERT_NOT_ALLOWED );
686 
687  rs.push(rec);
688  lnrows++;
689  leof = false;
690 }
691 
692 
694  if ((lfetch) && (rs.count() == 0)) { //First time
695  rs.push(newRecord()); //At least one record is needed
696 
697  if (laccum) {
698  lnrows = 0;
699  leof = false; //See note in the startFetch() method
700  while (fetch(lnrows, false)) {
701  rs.push(newRecord());
702  lnrows++;
703  leof = false;
704  }
705 
706  //laccum true implies lrandom=true and lknow_nrows=true
707  //lrandom = true;
708  //lknow_nrows = true;
709  setFirst();
710  }
711  else {
712  leof = false; //This is because inside fetch() a derived class
713  //must use the rec() method to access current
714  //record. If leof is true the rec() method would
715  //throw an exception. Anyway leof is not
716  //accessible in derived classes.
717  leof = ! fetch(0, false);
718  }
719  }
720 }
721 
722 
723 bool mcs::RecordSet::internal_fetch(unsigned int newpos) {
724  if (lpos != newpos) {
725  if (lusemetarec)
726  rs[current].emptyName();
727 
728  if (laccum) {
729  current = lpos = newpos;
730  leof = (lpos == lnrows); //(lpos == (lnrows-1));
731  }
732  else {
733  leof = false; //See note in the startFetch() method
734  leof = ! fetch(newpos, ( newpos == (lpos+1) ? false : true) );
735  lpos = newpos;
736  }
737  }
738 
739  return ! leof;
740 }
741 
742 
743 bool mcs::RecordSet::fetch(unsigned int newpos, bool random) {
744  if (lfetch)
745  throw MCS_ERROR(MSG_METHOD_MUST_BE_OVERLOADED, "RecordSet::fetch");
746 
747  return false;
748 }
749 
750 
751 
752 
753 bool mcs::RecordSet::know_nRows() { return lknow_nrows; }
754 
755 unsigned int mcs::RecordSet::nRows() {
756  if (! lknow_nrows)
757  throw MCS_ERROR( MSG_DONT_KNOW_NROWS );
758 
759  return lnrows;
760 }
761 
762 
763 
764 
766  if (rs.count() > 0)
767  return rs[current].count();
768  else if (lusemetarec)
769  return lmetarec.count();
770  else
771  return 0;
772 }
773 
774 
775 unsigned int mcs::RecordSet::pos() { return lpos; }
776 
777 bool mcs::RecordSet::eof() { return leof; }
778 
779 bool mcs::RecordSet::alwaysSameStructure() { return lusemetarec; }
780 
781 
782 Record& mcs::RecordSet::metarec()
783 {
784  if (! lusemetarec)
785  throw MCS_ERROR( MSG_NO_METAREC );
786 
787  return lmetarec;
788 }
789 
790 
791 Record& RecordSet::rec() {
792  if (leof)
793  throw MCS_ERROR( MSG_ALREADY_AT_END_OF_FILE );
794 
795  if (lusemetarec) {
796  for (int i=0; i<lmetarec.count(); i++)
797  rs[current][i].setName( lmetarec[i].name() );
798 
799  rs[current].setFieldMap( lmetarec);
800  }
801 
802  return rs[current];
803 }
804 
805 
806 
807 
808 
810  if (leof)
811  throw MCS_ERROR( MSG_ALREADY_AT_END_OF_FILE );
812 
813  return internal_fetch( lpos + 1 );
814 }
815 
816 
818 {
819  if (! lrandom)
820  throw MCS_ERROR( MSG_NOT_A_RANDOM_ACCESS_RECORDSET, "setPrev()" );
821 
822  if (lpos == 0)
823  throw MCS_ERROR( MSG_ALREADY_AT_BEGIN_OF_FILE );
824 
825  return internal_fetch( lpos - 1 );
826 }
827 
828 
830 {
831  if (! lrandom)
832  throw MCS_ERROR( MSG_NOT_A_RANDOM_ACCESS_RECORDSET, "setFirst()" );
833 
834  return internal_fetch( 0 );
835 }
836 
837 
838 
840  if (! lrandom)
841  throw MCS_ERROR( MSG_NOT_A_RANDOM_ACCESS_RECORDSET, "setLast()" );
842 
843  if (! lknow_nrows)
844  throw MCS_ERROR( MSG_DONT_KNOW_NROWS );
845 
846  return internal_fetch( lnrows - 1 );
847 }
848 
849 
850 bool mcs::RecordSet::setPos(unsigned int newpos)
851 {
852  if (! lrandom)
853  throw MCS_ERROR( MSG_NOT_A_RANDOM_ACCESS_RECORDSET, "setPos()" );
854 
855  if (! lknow_nrows)
856  throw MCS_ERROR( MSG_DONT_KNOW_NROWS );
857 
858  if (newpos >= lnrows)
859  throw MCS_ERROR( MSG_INDEX_OUT_RANGE, newpos, lnrows );
860 
861  return internal_fetch( newpos );
862 }
863 
864 
865 bool mcs::RecordSet::setWhere(int field, string equalTo)
866 {
867  if (field < 0)
868  throw MCS_ERROR(MSG_INVALID_POSITION, field);
869 
870  if (field >= nFields())
871  throw MCS_ERROR(MSG_INDEX_OUT_RANGE, field, nFields());
872 
873  if (! alwaysSameStructure())
874  throw MCS_ERROR( MSG_NO_SAME_META_INFO );
875 
876  bool found = false;
877 
878  if (lrandom)
879  setFirst();
880 
881  do {
882  if (rec()[field].sval() == equalTo) {
883  found = true;
884  break;
885  }
886  }
887  while (setNext());
888 
889  return found;
890 }
891 
892 
893 
894 bool mcs::RecordSet::setWhere(int field, int equalTo)
895 {
896  if (field < 0)
897  throw MCS_ERROR(MSG_INVALID_POSITION, field);
898 
899  if (field >= nFields())
900  throw MCS_ERROR(MSG_INDEX_OUT_RANGE, field, nFields());
901 
902  if (! alwaysSameStructure())
903  throw MCS_ERROR( MSG_NO_SAME_META_INFO );
904 
905  bool found = false;
906 
907  if (lrandom)
908  setFirst();
909 
910  do {
911  if (rec()[field].ival() == equalTo) {
912  found = true;
913  break;
914  }
915  }
916  while (setNext());
917 
918  return found;
919 }
920 
921 
922 
923 
924 void mcs::RecordSet::dump(string fn) {
925  hk_dump(fn);
926 }
927 
928 void mcs::RecordSet::hk_dump(string fn) {}
929 
930 
931 Record* mcs::RecordSet::prepRecToSend()
932 {
933  Record* ret = new Record(false);
934  long int nrows = (long int) lnrows;
935 
936  Data d(nrows);
937  d.setTag(code);
938 
939  ret->addField(d);
940 
941  if (lusemetarec)
942  for (int i=0; i<lmetarec.count(); i++)
943  ret->addField(lmetarec[i]);
944 
945  return ret;
946 }
947 
948 
virtual bool fetch(unsigned int newpos, bool random)
The virtual method to fetch new records.
Definition: Record.cc:743
#define MCS_RS_INSERT
Flag for RecordSet::init().
Definition: mcs.hh:4480
bool lusemetarec
If all records share the same meta structure.
Definition: mcs.hh:4531
#define MCS_RS_ACCUM
Flag for RecordSet::init().
Definition: mcs.hh:4437
void free()
Free allocated buffer.
Definition: Record.cc:68
int posWhoseNameIs(string name, enum ThrowExceptions throwexc=THROW)
Return the index of the first Data objects whose name is "name".
Definition: Record.cc:457
bool setPrev()
Set the record pointer to the previous position in the set.
Definition: Record.cc:817
short int lid
General purpose identificator.
Definition: mcs.hh:4513
#define MCS_RS_USEMETAREC
Flag for RecordSet::init().
Definition: mcs.hh:4449
Serialize memory buffers or files into chunks.
Definition: mcs.hh:1290
void setFieldMap(string s="")
Creates a new field map from the given string.
Definition: Record.cc:480
unsigned char code
Flags used in the init() method.
Definition: mcs.hh:4516
A simple class to implement "critical sections".
Definition: mcs.hh:2187
Buffer & operator>>(void *extbuf)
Copy data into an external buffer.
Definition: Record.cc:165
string smap
String representation of the map.
Definition: mcs.hh:4182
unsigned int size()
Return size of the buffer.
Definition: Record.cc:208
string sval(bool addWhiteSpaces=false) const
Convert internal data to a string object.
Definition: Data.cc:1555
unsigned int objSize()
Return how many bytes require the object to be serialized.
Definition: Record.cc:281
Buffer & operator<<(const void *extbuf)
Copy data from an external buffer.
Definition: Record.cc:118
void setTag(unsigned char tag)
Set a new value to internal tag.
Definition: Data.cc:2544
bool setLast()
Set the record pointer to the last position.
Definition: Record.cc:839
bool setPos(unsigned int i)
Set the record pointer to the i-th position.
Definition: Record.cc:850
bool linsert
If true the insert mechanism will be used.
Definition: mcs.hh:4537
BufferFreeOnDestroy
Values to be used in Buffer class constructor.
Definition: mcs.hh:246
char * operator[](unsigned int pos)
Use the Buffer class an an array of pointers to char.
Definition: Record.cc:199
void synchronize(bool setactive)
Enable or disable the synchronization feature.
Definition: Thread.cc:89
bool lknow_nrows
If the number of records is known.
Definition: mcs.hh:4519
Buffer(enum BufferFreeOnDestroy freeBuffer=AUTO_FREE)
Constructor, buffer allocation is handled internally.
Definition: Record.cc:28
bool serialize_buffer(char *&from, unsigned int &size)
Prepare a buffer with all informations contained in the object.
Definition: Record.cc:299
unsigned int current
Internal position in the Dynamic_Array object.
Definition: mcs.hh:4543
string name()
Return the name of the object.
Definition: Data.cc:1193
A dynamic array of Data objects.
Definition: mcs.hh:4170
char * buf
Pointer to temporary buffer containing the next chunk.
Definition: mcs.hh:1296
bool setFirst()
Set the record pointer to the first position.
Definition: Record.cc:829
bool laccum
If all records has been fetched during the init() call.
Definition: mcs.hh:4525
BASE pop(int pos=0)
Extracts an element from the array.
Definition: mcs.hh:4072
virtual ~RecordSet()
Destructor.
Definition: Record.cc:585
void push(BASE *d)
Push an existing element at the end of the array.
Definition: mcs.hh:4043
void setNull()
Set all Data object&#39;s name to null values.
Definition: Record.cc:516
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
Definition: mcs.hh:964
Data & operator[](string name)
Definition: Record.cc:439
char * from
Pointer to source buffer, if type = MCS_SERIAL_BUFFER.
Definition: mcs.hh:1311
bool leof
If the current position (lpos) is at the end of the set.
Definition: mcs.hh:4549
string Types2Str(Types type, bool isunsigned)
Return the name of the type given in "type" and "isunsigned".
Definition: Data.cc:313
string asString(string sep="\)
Return record content as a unique string.
Definition: Record.cc:524
bool internal_fetch(unsigned int newpos)
Fetch a new Record object in the set.
Definition: Record.cc:723
unsigned int size()
If knowSize() is true, return the size of the entire block of data.
Data field(string name)
Returns the Data object in the vector whose name is "name".
Definition: Record.cc:419
High level buffer.
Definition: mcs.hh:1095
int nFields()
Returns number of fields.
Definition: Record.cc:765
void resize(unsigned int size)
Check size, and eventually enlarge allocated memory.
Definition: Record.cc:81
int type
Type of data to be sent.
Definition: mcs.hh:1308
virtual void hk_dump(string fn)
Virtual method to provide dump facility to a file.
Definition: Record.cc:928
void startFetch()
Must be called when record fetching is possible.
Definition: Record.cc:693
Record & operator=(Record &from)
Assignment operator, will copy all data objects.
Definition: Record.cc:269
vector< string > split(string s, string sep=" ")
Split a string into tokens.
Definition: Utils.cc:192
void insert(Record *rec)
Insert a new record in the set.
Definition: Record.cc:673
#define MCS_CRITICAL_SECTION_END
End a critical section, there must be no "return" or "goto" instruction inside the section...
Definition: mcs.hh:2380
Main include file for all MCS based applications.
void setFieldMap(string s="")
Set up a field map for each record in the recordset.
Definition: Record.cc:590
bool setWhere(int i, string equalTo)
Set the record pointer to the position which satisfies a string condition.
Definition: Record.cc:865
RecordSet()
Build an empty record set.
Definition: Record.cc:577
void addField(Data *d)
Wrapper around Dynamic_Array.push.
Definition: Record.cc:364
#define MCS_RS_KNOW_NROWS
Flag for RecordSet::init().
Definition: mcs.hh:4457
void emptyName()
Set all Data object&#39;s name to an empty string.
Definition: Record.cc:508
Record(Record &from)
Copy constructor, will copy all data objects.
Definition: Record.cc:259
void init(unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0)
Initailize the Record set.
Definition: Record.cc:638
A general purpose data type.
Definition: mcs.hh:3092
#define MCS_RS_RANDOM
Flag for RecordSet::init().
Definition: mcs.hh:4466
Dynamic_Array< Record > rs
Internal Record set.
Definition: mcs.hh:4552
void clear()
Empty the array.
Definition: mcs.hh:4130
virtual Record * newRecord()
Creates a new Record object in the heap.
Definition: Record.cc:601
ThrowExceptions
Values to be used with throwexc parameters.
Definition: mcs.hh:257
bool lrandom
If random access (setFirst, setLast, setPos) is allowed.
Definition: mcs.hh:4528
~Buffer()
Destructor, will free the buffer if "freeBuffer" is true.
Definition: Record.cc:64
~Record()
Destructor.
Definition: Record.cc:234
string trim(string s)
Remove any leading or trailing blanks.
Definition: Utils.cc:160
int count()
Wrapper around Dynamic_Array.count.
Definition: Record.cc:359
#define MCS_FATAL(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
Definition: mcs.hh:967
bool setNext()
Set the record pointer to the next position.
Definition: Record.cc:809
#define MCS_CRITICAL_SECTION_BEGIN
Start a critical section, there must be no "return" or "goto" instruction inside the section...
Definition: mcs.hh:2375
Record lmetarec
Record of meta structure, to be used only if lusemetarec is true.
Definition: mcs.hh:4546
unsigned int lnrows
Number of records, to be used only if lknow_nrows is true.
Definition: mcs.hh:4522
Dynamic_Array< int > lmap
Array of mapped fields.
Definition: mcs.hh:4179
int count()
Returns number of elements in the array.
Definition: mcs.hh:4118
Buffer & operator()(unsigned int start, unsigned int len)
Select a "window" in the buffer.
Definition: Record.cc:109
Dynamic_Array< Data > array
Array of fields.
Definition: mcs.hh:4176
unsigned int objSize()
Return how many bytes require the object to be serialized.
Definition: Data.cc:2305
unsigned int lpos
Current position in the recordset.
Definition: mcs.hh:4540
Namespace for MCS library.
bool lfetch
If true the fetch mechanism will be used.
Definition: mcs.hh:4534

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018