cMsg Messaging System  6.0
 All Classes Namespaces Files Functions Variables Friends
cMsgPayload.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*
2 * Copyright (c) 2007 Jefferson Science Associates, *
3 * Thomas Jefferson National Accelerator Facility *
4 * *
5 * This software was developed under a United States Government license *
6 * described in the NOTICE file included as part of this distribution. *
7 * *
8 * C.Timmer, 3-Aug-2007, Jefferson Lab *
9 * *
10 * Authors: Carl Timmer *
11 * timmer@jlab.org Jefferson Lab, MS-12B3 *
12 * Phone: (757) 269-5130 12000 Jefferson Ave. *
13 * Fax: (757) 269-6248 Newport News, VA 23606 *
14 * *
15 *----------------------------------------------------------------------------*/
16 
17 
18 #include <cMsg.hxx>
19 #include <cMsgPrivate.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <pthread.h>
24 #include <vector>
25 #include <map>
26 #include <sstream>
27 
28 using namespace std;
29 using namespace cmsg;
30 
31 namespace cmsg {
32 
33  //-----------------------------------------------------------------------------
34  // cMsgPayload methods
35  //-----------------------------------------------------------------------------
36 
37 
38  //-----------------------------------------------------------------------------
39 
44  void cMsgMessage::payloadClear(void) {
45  cMsgPayloadClear(myMsgPointer);
46  }
47 
48  //-----------------------------------------------------------------------------
49 
56  void cMsgMessage::payloadReset(void) {
57  cMsgPayloadReset(myMsgPointer);
58  }
59 
60  //-------------------------------------------------------------------
61 
65  void cMsgMessage::payloadPrint(void) const {
66  cMsgPayloadPrint(myMsgPointer);
67  }
68 
69  //-------------------------------------------------------------------
70 
76  bool cMsgMessage::hasPayload() const {
77  int hasPayload;
78  cMsgHasPayload(myMsgPointer, &hasPayload);
79  return hasPayload ? true : false;
80  }
81 
82  //-------------------------------------------------------------------
83 
90  bool cMsgMessage::payloadContainsName(const string &name) const {
91  return cMsgPayloadContainsName(myMsgPointer, name.c_str()) ? true : false;
92  }
93 
94  //-------------------------------------------------------------------
95 
101  int cMsgMessage::payloadGetCount() const {
102  int count;
103  cMsgPayloadGetCount(myMsgPointer, &count);
104  return count;
105  }
106 
107  //-------------------------------------------------------------------
108 
148  int cMsgMessage::payloadGetType(const string &name) const
149  throw(cMsgException) {
150  int err, type;
151  err = cMsgPayloadGetType(myMsgPointer, name.c_str(), &type);
152  if (err != CMSG_OK) {
153  if (err == CMSG_BAD_ARGUMENT)
154  throw(cMsgException("Name is null"));
155  else
156  throw(cMsgException(string("No payload item named ") + name));
157  }
158  return type;
159  }
160 
161  //-------------------------------------------------------------------
162 
170  void cMsgMessage::payloadCopy(const cMsgMessage &msg) throw(cMsgException) {
171  int err = cMsgPayloadCopy(msg.myMsgPointer, myMsgPointer);
172  if (err!= CMSG_OK) {
173  throw(cMsgException(cMsgPerror(err),err));
174  }
175  }
176 
177  //-------------------------------------------------------------------
178 
185  string cMsgMessage::payloadGetText() const {
186  const char *txt;
187  cMsgGetPayloadText(myMsgPointer, &txt);
188  string s(txt);
189  return s;
190  }
191 
192  //-------------------------------------------------------------------
193 
201  void cMsgMessage::payloadSetFromText(const string &txt)
202  throw(cMsgException) {
203  int err = cMsgPayloadSetAllFieldsFromText(myMsgPointer, txt.c_str());
204  if (err != CMSG_OK) {
205  throw(cMsgException(cMsgPerror(err),err));
206  }
207  return;
208  }
209 
210  //-------------------------------------------------------------------
211 
218  string cMsgMessage::payloadGetFieldDescription(const string &name) const
219  throw(cMsgException) {
220  const char *field = cMsgPayloadFieldDescription(myMsgPointer, name.c_str());
221  if (field == NULL) {
222  string err("No such field as ");
223  err += field;
224  throw(cMsgException(err));
225  }
226  string s(field);
227  return s;
228  }
229 
230  //-------------------------------------------------------------------
231 
240  map<string,int> *cMsgMessage::payloadGet() const throw(cMsgException) {
241  char **names;
242  int *types, len;
243 
244  int err = cMsgPayloadGetInfo(myMsgPointer, &names, &types, &len);
245  if (err != CMSG_OK) {
246  if (err == CMSG_BAD_ARGUMENT)
247  throw(cMsgException("Name is null"));
248  else if (err == CMSG_ERROR)
249  throw(cMsgException("No payload exists"));
250  else
251  throw(cMsgException("Out of memory"));
252  }
253 
254  map<string,int> *mp = new map<string,int>;
255  for (int i=0; i<len; i++) {
256  (*mp)[names[i]] = types[i];
257  }
258  return mp;
259  }
260 
261  //-------------------------------------------------------------------
262 
271  bool cMsgMessage::payloadRemoveField(const string &name) {
272  return cMsgPayloadRemove(myMsgPointer, name.c_str()) == 0 ? false : true;
273  }
274 
275 
276  //-------------------------------------------------------------------
277 
287  void cMsgMessage::setHistoryLengthMax(int len) const throw(cMsgException) {
288  int err = cMsgSetHistoryLengthMax(myMsgPointer, len);
289  if (err != CMSG_OK) throw (cMsgException("len must be >= 0 and < CMSG_HISTORY_LENGTH_ABS_MAX"));
290  }
291 
292 
293 //-------------------------------------------------------------------
294 // GET VALUE METHODS
295 //-------------------------------------------------------------------
296 
297 //-------------------------------------------------------------------
298 // BINARY
299 //-------------------------------------------------------------------
300 
312 void cMsgMessage::getBinary(const string &name, const char **val, int &len, int &endian)
313  const throw(cMsgException) {
314  int err = cMsgGetBinary(myMsgPointer, name.c_str(), val, &len, &endian);
315  if (err != CMSG_OK) {
316  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
317  else throw(cMsgException(string("No payload item named ") + name));
318  }
319  return;
320 }
321 
335 void cMsgMessage::getBinaryArray(const string &name, const char ***vals,
336  int **lens, int **endians, int &count)
337  const throw(cMsgException) {
338  int err = cMsgGetBinaryArray(myMsgPointer, name.c_str(), vals, lens, endians, &count);
339  if (err != CMSG_OK) {
340  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
341  else throw(cMsgException(string("No payload item named ") + name));
342  }
343  return;
344 }
345 
346 //-------------------------------------------------------------------
347 // CMSG MESSAGES
348 //-------------------------------------------------------------------
349 
359 cMsgMessage *cMsgMessage::getMessage(const string &name) const throw(cMsgException) {
360  const void *val;
361  int err = cMsgGetMessage(myMsgPointer, name.c_str(), &val);
362  if (err != CMSG_OK) {
363  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
364  else throw(cMsgException(string("No payload item named ") + name));
365  }
366 
367  // copy message
368  void *newMsgPointer=cMsgCopyMessage(val);
369  if(newMsgPointer==NULL)
370  throw(cMsgException("?cMsgMessage::getMessage...unable to create new message from message contents",CMSG_ERROR));
371 
372  return(new cMsgMessage(newMsgPointer));
373 }
374 
375 
376 //-------------------------------------------------------------------
377 
378 
389 vector<cMsgMessage*> *cMsgMessage::getMessagePVector(const string &name) const throw(cMsgException) {
390  int len;
391  const void **vals;
392  int err = cMsgGetMessageArray(myMsgPointer, name.c_str(), &vals, &len);
393  if (err != CMSG_OK) {
394  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
395  else throw(cMsgException(string("No payload item named ") + name));
396  }
397 
398 
399  // fill new vector with message copies
400  vector<cMsgMessage*> *msgPVec = new vector<cMsgMessage*>;
401  for (int i=0; i<len; i++) msgPVec->push_back(new cMsgMessage(cMsgCopyMessage(vals[i])));
402 
403  return(msgPVec);
404 }
405 
406 
407 //-------------------------------------------------------------------
408 
409 
420 vector<cMsgMessage> *cMsgMessage::getMessageVector(const string &name) const throw(cMsgException) {
421  int len;
422  const void **vals;
423  int err = cMsgGetMessageArray(myMsgPointer, name.c_str(), &vals, &len);
424  if (err != CMSG_OK) {
425  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
426  else throw(cMsgException(string("No payload item named ") + name));
427  }
428 
429 
430  // fill new vector with message copies
431  vector<cMsgMessage> *msgVec = new vector<cMsgMessage>;
432  for (int i=0; i<len; i++) msgVec->push_back(cMsgMessage(cMsgCopyMessage(vals[i])));
433 
434  return(msgVec);
435 }
436 
437 
438 //-------------------------------------------------------------------
439 
440 
451 cMsgMessage* *cMsgMessage::getMessagePArray(const string &name) const throw(cMsgException) {
452  int len;
453  const void **vals;
454  int err = cMsgGetMessageArray(myMsgPointer, name.c_str(), &vals, &len);
455  if (err != CMSG_OK) {
456  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
457  else throw(cMsgException(string("No payload item named ") + name));
458  }
459 
460  // create and fill array with pointers to message copies
461  cMsgMessage* *msgPArray = new cMsgMessage*[len];
462  for (int i=0; i<len; i++) msgPArray[i]=(new cMsgMessage(cMsgCopyMessage(vals[i])));
463 
464  return(msgPArray);
465 }
466 
467 
468 //-------------------------------------------------------------------
469 
470 
481 cMsgMessage *cMsgMessage::getMessageArray(const string &name) const throw(cMsgException) {
482  int len;
483  const void **vals;
484  int err = cMsgGetMessageArray(myMsgPointer, name.c_str(), &vals, &len);
485  if (err != CMSG_OK) {
486  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
487  else throw(cMsgException(string("No payload item named ") + name));
488  }
489 
490  // create and fill array with message copies
491  cMsgMessage *msgArray = new cMsgMessage[len];
492  for (int i=0; i<len; i++) msgArray[i]=(cMsgMessage(cMsgCopyMessage(vals[i])));
493 
494  return(msgArray);
495 }
496 
497 
498 //-------------------------------------------------------------------
499 // STRINGS
500 //-------------------------------------------------------------------
501 
509 string cMsgMessage::getString(const string &name) const throw(cMsgException) {
510  const char *val;
511  int err = cMsgGetString(myMsgPointer, name.c_str(), &val);
512  if (err != CMSG_OK) {
513  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
514  else throw(cMsgException(string("No payload item named ") + name));
515  }
516  string s(val);
517  return s;
518 }
519 
520 
521 //-------------------------------------------------------------------
522 
523 
533 vector<string> *cMsgMessage::getStringVector(const string &name) const throw(cMsgException) {
534  int len;
535  const char **vals;
536  int err = cMsgGetStringArray(myMsgPointer, name.c_str(), &vals, &len);
537  if (err != CMSG_OK) {
538  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
539  else throw(cMsgException(string("No payload item named ") + name));
540  }
541 
542  // copy array values and put into a vector
543  vector<string> *strs = new vector<string>;
544  for (int i=0; i<len; i++) strs->push_back(string(vals[i]));
545  return strs;
546 }
547 
548 
549 //-------------------------------------------------------------------
550 
551 
561 string *cMsgMessage::getStringArray(const string &name) const throw(cMsgException) {
562  int len;
563  const char **vals;
564  int err = cMsgGetStringArray(myMsgPointer, name.c_str(), &vals, &len);
565  if (err != CMSG_OK) {
566  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
567  else throw(cMsgException(string("No payload item named ") + name));
568  }
569 
570  // place strings into new array
571  string *strs = new string[len];
572  for (int i=0; i<len; i++) strs[i]=string(vals[i]);
573  return strs;
574 }
575 
576 
577 //-------------------------------------------------------------------
578 // REALS
579 //-------------------------------------------------------------------
580 
588 float cMsgMessage::getFloat(const string &name) const throw(cMsgException) {
589  float val;
590  int err = cMsgGetFloat(myMsgPointer, name.c_str(), &val);
591  if (err != CMSG_OK) {
592  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
593  else throw(cMsgException(string("No payload item named ") + name));
594  }
595  return val;
596 }
597 
598 //-------------------------------------------------------------------
599 
607 double cMsgMessage::getDouble(const string &name) const throw(cMsgException) {
608  double val;
609  int err = cMsgGetDouble(myMsgPointer, name.c_str(), &val);
610  if (err != CMSG_OK) {
611  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
612  else throw(cMsgException(string("No payload item named ") + name));
613  }
614  return val;
615 }
616 
617 //-------------------------------------------------------------------
618 // REAL ARRAYS
619 //-------------------------------------------------------------------
620 
621 
631 vector<float> *cMsgMessage::getFloatVector(const string &name) const throw(cMsgException) {
632  int len;
633  const float *vals;
634  int err = cMsgGetFloatArray(myMsgPointer, name.c_str(), &vals, &len);
635  if (err != CMSG_OK) {
636  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
637  else throw(cMsgException(string("No payload item named ") + name));
638  }
639  // put array values into a vector
640  vector<float> *flts = new vector<float>;
641  for (int i=0; i<len; i++) flts->push_back(vals[i]);
642  return flts;
643 }
644 
645 
646 //-------------------------------------------------------------------
647 
648 
658 float *cMsgMessage::getFloatArray(const string &name) const throw(cMsgException) {
659  int len;
660  const float *vals;
661  int err = cMsgGetFloatArray(myMsgPointer, name.c_str(), &vals, &len);
662  if (err != CMSG_OK) {
663  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
664  else throw(cMsgException(string("No payload item named ") + name));
665  }
666 
667  // copy values into a new array
668  float *flts = new float[len];
669  for (int i=0; i<len; i++) flts[i]=vals[i];
670  return flts;
671 }
672 
673 
674 //-------------------------------------------------------------------
675 
676 
686 vector<double> *cMsgMessage::getDoubleVector(const string &name) const throw(cMsgException) {
687  int len;
688  const double *vals;
689  int err = cMsgGetDoubleArray(myMsgPointer, name.c_str(), &vals, &len);
690  if (err != CMSG_OK) {
691  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
692  else throw(cMsgException(string("No payload item named ") + name));
693  }
694  // put array values into a vector
695  vector<double> *dbls = new vector<double>;
696  for (int i=0; i<len; i++) dbls->push_back(vals[i]);
697  return dbls;
698 }
699 
700 
701 
702 //-------------------------------------------------------------------
703 
704 
714 double *cMsgMessage::getDoubleArray(const string &name) const throw(cMsgException) {
715  int len;
716  const double *vals;
717  int err = cMsgGetDoubleArray(myMsgPointer, name.c_str(), &vals, &len);
718  if (err != CMSG_OK) {
719  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
720  else throw(cMsgException(string("No payload item named ") + name));
721  }
722 
723  // put values into new array
724  double *dbls = new double[len];
725  for (int i=0; i<len; i++) dbls[i]=vals[i];
726  return dbls;
727 }
728 
729 
730 //-------------------------------------------------------------------
731 // INTS
732 //-------------------------------------------------------------------
733 
741 int8_t cMsgMessage::getInt8(const string &name) const throw(cMsgException) {
742  int8_t val;
743  int err = cMsgGetInt8(myMsgPointer, name.c_str(), &val);
744  if (err != CMSG_OK) {
745  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
746  else throw(cMsgException(string("No payload item named ") + name));
747  }
748  return val;
749 }
750 
751 //-------------------------------------------------------------------
752 
760 int16_t cMsgMessage::getInt16(const string &name) const throw(cMsgException) {
761  int16_t val;
762  int err = cMsgGetInt16(myMsgPointer, name.c_str(), &val);
763  if (err != CMSG_OK) {
764  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
765  else throw(cMsgException(string("No payload item named ") + name));
766  }
767  return val;
768 }
769 
770 //-------------------------------------------------------------------
771 
779 int32_t cMsgMessage::getInt32(const string &name) const throw(cMsgException) {
780  int32_t val;
781  int err = cMsgGetInt32(myMsgPointer, name.c_str(), &val);
782  if (err != CMSG_OK) {
783  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
784  else throw(cMsgException(string("No payload item named ") + name));
785  }
786  return val;
787 }
788 
789 //-------------------------------------------------------------------
790 
798 int64_t cMsgMessage::getInt64(const string &name) const throw(cMsgException) {
799  int64_t val;
800  int err = cMsgGetInt64(myMsgPointer, name.c_str(), &val);
801  if (err != CMSG_OK) {
802  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
803  else throw(cMsgException(string("No payload item named ") + name));
804  }
805  return val;
806 }
807 
808 //-------------------------------------------------------------------
809 
817 uint8_t cMsgMessage::getUint8(const string &name) const throw(cMsgException) {
818  uint8_t val;
819  int err = cMsgGetUint8(myMsgPointer, name.c_str(), &val);
820  if (err != CMSG_OK) {
821  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
822  else throw(cMsgException(string("No payload item named ") + name));
823  }
824  return val;
825 }
826 
827 //-------------------------------------------------------------------
828 
836 uint16_t cMsgMessage::getUint16(const string &name) const throw(cMsgException) {
837  uint16_t val;
838  int err = cMsgGetUint16(myMsgPointer, name.c_str(), &val);
839  if (err != CMSG_OK) {
840  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
841  else throw(cMsgException(string("No payload item named ") + name));
842  }
843  return val;
844 }
845 
846 //-------------------------------------------------------------------
847 
855 uint32_t cMsgMessage::getUint32(const string &name) const throw(cMsgException) {
856  uint32_t val;
857  int err = cMsgGetUint32(myMsgPointer, name.c_str(), &val);
858  if (err != CMSG_OK) {
859  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
860  else throw(cMsgException(string("No payload item named ") + name));
861  }
862  return val;
863 }
864 
865 //-------------------------------------------------------------------
866 
874 uint64_t cMsgMessage::getUint64(const string &name) const throw(cMsgException) {
875  uint64_t val;
876  int err = cMsgGetUint64(myMsgPointer, name.c_str(), &val);
877  if (err != CMSG_OK) {
878  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
879  else throw(cMsgException(string("No payload item named ") + name));
880  }
881  return val;
882 }
883 
884 //-------------------------------------------------------------------
885 // INT ARRAYS & VECTORS
886 //-------------------------------------------------------------------
887 
897 vector<int8_t> *cMsgMessage::getInt8Vector(const string &name) const throw(cMsgException) {
898  int len;
899  const int8_t *vals;
900  int err = cMsgGetInt8Array(myMsgPointer, name.c_str(), &vals, &len);
901  if (err != CMSG_OK) {
902  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
903  else throw(cMsgException(string("No payload item named ") + name));
904  }
905  // put array values into a vector
906  vector<int8_t> *ints = new vector<int8_t>;
907  for (int i=0; i<len; i++) ints->push_back(vals[i]);
908  return ints;
909 }
910 
911 
912 //-------------------------------------------------------------------
913 
914 
924 int8_t *cMsgMessage::getInt8Array(const string &name) const throw(cMsgException) {
925  int len;
926  const int8_t *vals;
927  int err = cMsgGetInt8Array(myMsgPointer, name.c_str(), &vals, &len);
928  if (err != CMSG_OK) {
929  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
930  else throw(cMsgException(string("No payload item named ") + name));
931  }
932  // put values into new array
933  int8_t *ints = new int8_t[len];
934  for (int i=0; i<len; i++) ints[i]=vals[i];
935  return ints;
936 }
937 
938 
939 //-------------------------------------------------------------------
940 
941 
951 vector<int16_t> *cMsgMessage::getInt16Vector(const string &name) const throw(cMsgException) {
952  int len;
953  const int16_t *vals;
954  int err = cMsgGetInt16Array(myMsgPointer, name.c_str(), &vals, &len);
955  if (err != CMSG_OK) {
956  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
957  else throw(cMsgException(string("No payload item named ") + name));
958  }
959  // put array values into a vector
960  vector<int16_t> *ints = new vector<int16_t>;
961  for (int i=0; i<len; i++) ints->push_back(vals[i]);
962  return ints;
963 }
964 
965 
966 //-------------------------------------------------------------------
967 
968 
978 int16_t *cMsgMessage::getInt16Array(const string &name) const throw(cMsgException) {
979  int len;
980  const int16_t *vals;
981  int err = cMsgGetInt16Array(myMsgPointer, name.c_str(), &vals, &len);
982  if (err != CMSG_OK) {
983  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
984  else throw(cMsgException(string("No payload item named ") + name));
985  }
986  // put values into new array
987  int16_t *ints = new int16_t[len];
988  for (int i=0; i<len; i++) ints[i]=vals[i];
989  return ints;
990 }
991 
992 
993 //-------------------------------------------------------------------
994 
995 
1005 vector<int32_t> *cMsgMessage::getInt32Vector(const string &name) const throw(cMsgException) {
1006  int len;
1007  const int32_t *vals;
1008  int err = cMsgGetInt32Array(myMsgPointer, name.c_str(), &vals, &len);
1009  if (err != CMSG_OK) {
1010  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1011  else throw(cMsgException(string("No payload item named ") + name));
1012  }
1013  // put array values into a vector
1014  vector<int32_t> *ints = new vector<int32_t>;
1015  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1016  return ints;
1017 }
1018 
1019 
1020 //-------------------------------------------------------------------
1021 
1022 
1032 int32_t *cMsgMessage::getInt32Array(const string &name) const throw(cMsgException) {
1033  int len;
1034  const int32_t *vals;
1035  int err = cMsgGetInt32Array(myMsgPointer, name.c_str(), &vals, &len);
1036  if (err != CMSG_OK) {
1037  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1038  else throw(cMsgException(string("No payload item named ") + name));
1039  }
1040  // put values into new array
1041  int32_t *ints = new int32_t[len];
1042  for (int i=0; i<len; i++) ints[i]=vals[i];
1043  return ints;
1044 }
1045 
1046 
1047 //-------------------------------------------------------------------
1048 
1049 
1059 vector<int64_t> *cMsgMessage::getInt64Vector(const string &name) const throw(cMsgException) {
1060  int len;
1061  const int64_t *vals;
1062  int err = cMsgGetInt64Array(myMsgPointer, name.c_str(), &vals, &len);
1063  if (err != CMSG_OK) {
1064  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1065  else throw(cMsgException(string("No payload item named ") + name));
1066  }
1067  // put array values into a vector
1068  vector<int64_t> *ints = new vector<int64_t>;
1069  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1070  return ints;
1071 }
1072 
1073 
1074 //-------------------------------------------------------------------
1075 
1076 
1086 int64_t *cMsgMessage::getInt64Array(const string &name) const throw(cMsgException) {
1087  int len;
1088  const int64_t *vals;
1089  int err = cMsgGetInt64Array(myMsgPointer, name.c_str(), &vals, &len);
1090  if (err != CMSG_OK) {
1091  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1092  else throw(cMsgException(string("No payload item named ") + name));
1093  }
1094  // put values into new array
1095  int64_t *ints = new int64_t[len];
1096  for (int i=0; i<len; i++) ints[i]=vals[i];
1097  return ints;
1098 }
1099 
1100 
1101 //-------------------------------------------------------------------
1102 
1103 
1114 vector<uint8_t> *cMsgMessage::getUint8Vector(const string &name) const throw(cMsgException) {
1115  int len;
1116  const uint8_t *vals;
1117  int err = cMsgGetUint8Array(myMsgPointer, name.c_str(), &vals, &len);
1118  if (err != CMSG_OK) {
1119  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1120  else throw(cMsgException(string("No payload item named ") + name));
1121  }
1122  // put array values into a vector
1123  vector<uint8_t> *ints = new vector<uint8_t>;
1124  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1125  return ints;
1126 }
1127 
1128 
1129 //-------------------------------------------------------------------
1130 
1131 
1142 uint8_t *cMsgMessage::getUint8Array(const string &name) const throw(cMsgException) {
1143  int len;
1144  const uint8_t *vals;
1145  int err = cMsgGetUint8Array(myMsgPointer, name.c_str(), &vals, &len);
1146  if (err != CMSG_OK) {
1147  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1148  else throw(cMsgException(string("No payload item named ") + name));
1149  }
1150  // put values into new array
1151  uint8_t *ints = new uint8_t[len];
1152  for (int i=0; i<len; i++) ints[i]=vals[i];
1153  return ints;
1154 }
1155 
1156 
1157 //-------------------------------------------------------------------
1158 
1159 
1170 vector<uint16_t> *cMsgMessage::getUint16Vector(const string &name) const throw(cMsgException) {
1171  int len;
1172  const uint16_t *vals;
1173  int err = cMsgGetUint16Array(myMsgPointer, name.c_str(), &vals, &len);
1174  if (err != CMSG_OK) {
1175  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1176  else throw(cMsgException(string("No payload item named ") + name));
1177  }
1178  // put array values into a vector
1179  vector<uint16_t> *ints = new vector<uint16_t>;
1180  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1181  return ints;
1182 }
1183 
1184 
1185 //-------------------------------------------------------------------
1186 
1187 
1198 uint16_t *cMsgMessage::getUint16Array(const string &name) const throw(cMsgException) {
1199  int len;
1200  const uint16_t *vals;
1201  int err = cMsgGetUint16Array(myMsgPointer, name.c_str(), &vals, &len);
1202  if (err != CMSG_OK) {
1203  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1204  else throw(cMsgException(string("No payload item named ") + name));
1205  }
1206  // put values into new array
1207  uint16_t *ints = new uint16_t[len];
1208  for (int i=0; i<len; i++) ints[i]=vals[i];
1209  return ints;
1210 }
1211 
1212 
1213 //-------------------------------------------------------------------
1214 
1215 
1225 vector<uint32_t> *cMsgMessage::getUint32Vector(const string &name) const throw(cMsgException) {
1226  int len;
1227  const uint32_t *vals;
1228  int err = cMsgGetUint32Array(myMsgPointer, name.c_str(), &vals, &len);
1229  if (err != CMSG_OK) {
1230  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1231  else throw(cMsgException(string("No payload item named ") + name));
1232  }
1233  // put array values into a vector
1234  vector<uint32_t> *ints = new vector<uint32_t>;
1235  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1236  return ints;
1237 }
1238 
1239 
1240 //-------------------------------------------------------------------
1241 
1242 
1252 uint32_t *cMsgMessage::getUint32Array(const string &name) const throw(cMsgException) {
1253  int len;
1254  const uint32_t *vals;
1255  int err = cMsgGetUint32Array(myMsgPointer, name.c_str(), &vals, &len);
1256  if (err != CMSG_OK) {
1257  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1258  else throw(cMsgException(string("No payload item named ") + name));
1259  }
1260  // put values into new array
1261  uint32_t *ints = new uint32_t[len];
1262  for (int i=0; i<len; i++) ints[i]=vals[i];
1263  return ints;
1264 }
1265 
1266 
1267 //-------------------------------------------------------------------
1268 
1269 
1279 vector<uint64_t> *cMsgMessage::getUint64Vector(const string &name) const throw(cMsgException) {
1280  int len;
1281  const uint64_t *vals;
1282  int err = cMsgGetUint64Array(myMsgPointer, name.c_str(), &vals, &len);
1283  if (err != CMSG_OK) {
1284  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1285  else throw(cMsgException(string("No payload item named ") + name));
1286  }
1287  // put array values into a vector
1288  vector<uint64_t> *ints = new vector<uint64_t>;
1289  for (int i=0; i<len; i++) ints->push_back(vals[i]);
1290  return ints;
1291 }
1292 
1293 
1294 
1295 //-------------------------------------------------------------------
1296 
1297 
1307 uint64_t *cMsgMessage::getUint64Array(const string &name) const throw(cMsgException) {
1308  int len;
1309  const uint64_t *vals;
1310  int err = cMsgGetUint64Array(myMsgPointer, name.c_str(), &vals, &len);
1311  if (err != CMSG_OK) {
1312  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Wrong field type"));
1313  else throw(cMsgException(string("No payload item named ") + name));
1314  }
1315  // put values into new array
1316  uint64_t *ints = new uint64_t[len];
1317  for (int i=0; i<len; i++) ints[i]=vals[i];
1318  return ints;
1319 }
1320 
1321 
1322 //-------------------------------------------------------------------
1323 // ADD METHODS
1324 //-------------------------------------------------------------------
1325 
1326 //-------------------------------------------------------------------
1327 // BINARY
1328 //-------------------------------------------------------------------
1329 
1345 void cMsgMessage::add(const string &name, const char *src, int size, int endian) {
1346  int err = cMsgAddBinary(myMsgPointer, name.c_str(), src, size, endian);
1347  if (err != CMSG_OK) {
1348  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name or if error in binary-to-text conversion"));
1349  else if (err == CMSG_BAD_ARGUMENT) throw(cMsgException("src or name null, size < 1, or endian improper value"));
1350  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1351  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1352  else throw(cMsgException("Error"));
1353  }
1354 }
1355 
1372 void cMsgMessage::add(const string &name, const char **srcs, int number,
1373  const int sizes[], const int endians[]) {
1374  int err = cMsgAddBinaryArray(myMsgPointer, name.c_str(), srcs, number, sizes, endians);
1375  if (err != CMSG_OK) {
1376  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name or if error in binary-to-text conversion"));
1377  else if (err == CMSG_BAD_ARGUMENT) throw(cMsgException("srcs or name null, sizes < 1, or endians improper value"));
1378  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1379  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1380  else throw(cMsgException("Error"));
1381  }
1382 }
1383 
1384 
1385 
1386 //-------------------------------------------------------------------
1387 // CMSG STRINGS
1388 //-------------------------------------------------------------------
1389 
1400 void cMsgMessage::add(const string &name, const string &s) {
1401  int err = cMsgAddString(myMsgPointer, name.c_str(), s.c_str());
1402  if (err != CMSG_OK) {
1403  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1404  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1405  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1406  else throw(cMsgException("Error"));
1407  }
1408 }
1409 
1410 //-------------------------------------------------------------------
1411 
1422 void cMsgMessage::add(const string &name, const string *s) {
1423  add(name,*s);
1424 }
1425 
1426 //-------------------------------------------------------------------
1427 
1439 void cMsgMessage::add(const string &name, const char **strs, int len) {
1440  if (strs == NULL) throw (cMsgException("strs arg is null"));
1441  if (len < 1) throw (cMsgException("string array len < 1"));
1442 
1443  int err = cMsgAddStringArray(myMsgPointer, name.c_str(), strs, len);
1444  if (err != CMSG_OK) {
1445  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1446  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1447  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1448  else throw(cMsgException("Error"));
1449  }
1450 }
1451 
1452 //-------------------------------------------------------------------
1453 
1465 void cMsgMessage::add(const string &name, const string *strs, int len) {
1466  if (strs == NULL) throw (cMsgException("strs arg is null"));
1467  if (len < 1) throw (cMsgException("string array len < 1"));
1468 
1469 #ifdef linux
1470  const char *strings[len];
1471 #else
1472  const char **strings = (const char **)malloc(len*sizeof(char *));
1473  if (strings == NULL) throw(cMsgException("No memory available"));
1474 #endif
1475 
1476  for (int i=0; i<len; i++) {
1477  strings[i] = strs[i].c_str();
1478  }
1479 
1480  int err = cMsgAddStringArray(myMsgPointer, name.c_str(), strings, len);
1481 #ifndef linux
1482  free(strings);
1483 #endif
1484  if (err != CMSG_OK) {
1485  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1486  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1487  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1488  else throw(cMsgException("Error"));
1489  }
1490 
1491 }
1492 
1493 //-------------------------------------------------------------------
1494 
1505 void cMsgMessage::add(const string &name, const vector<string> &strs) {
1506  if (strs.size() < 1) throw(cMsgException("Zero length vector"));
1507 #ifdef linux
1508  const char *strings[strs.size()];
1509 #else
1510  const char **strings = (const char **)malloc(strs.size()*sizeof(char *));
1511  if (strings == NULL) throw(cMsgException("No memory available"));
1512 #endif
1513 
1514  for (vector<string>::size_type i=0; i < strs.size(); i++) {
1515  strings[i] = strs[i].c_str();
1516  }
1517 
1518  int err = cMsgAddStringArray(myMsgPointer, name.c_str(), strings, strs.size());
1519 #ifndef linux
1520  free(strings);
1521 #endif
1522  if (err != CMSG_OK) {
1523  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1524  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1525  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1526  else throw(cMsgException("Error"));
1527  }
1528 }
1529 
1540 void cMsgMessage::add(const string &name, const vector<string> *strs) {
1541  add(name,*strs);
1542 }
1543 
1544 //-------------------------------------------------------------------
1545 // CMSG MESSAGES
1546 //-------------------------------------------------------------------
1547 
1558 void cMsgMessage::add(const string &name, const cMsgMessage &msg) {
1559  int err = cMsgAddMessage(myMsgPointer, name.c_str(), msg.myMsgPointer);
1560  if (err != CMSG_OK) {
1561  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1562  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1563  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1564  else throw(cMsgException("Error"));
1565  }
1566 }
1567 
1568 //-------------------------------------------------------------------
1569 
1580 void cMsgMessage::add(const string &name, const cMsgMessage *msg) {
1581  add(name,*msg);
1582 }
1583 
1584 //-------------------------------------------------------------------
1585 
1586 
1598 void cMsgMessage::add(const string &name, const cMsgMessage *msg, int len) {
1599  if (msg == NULL) throw (cMsgException("msg arg is null"));
1600  if (len < 1) throw (cMsgException("cmsg message array len < 1"));
1601 
1602 #ifdef linux
1603  const void *msgs[len];
1604 #else
1605  const void **msgs = (const void **)malloc(len*sizeof(void *));
1606  if (msgs == NULL) throw(cMsgException("No memory available"));
1607 #endif
1608 
1609  for (int i=0; i<len; i++) {
1610  msgs[i] = msg[i].myMsgPointer;
1611  }
1612 
1613  int err = cMsgAddMessageArray(myMsgPointer, name.c_str(), msgs, len);
1614 #ifndef linux
1615  free(msgs);
1616 #endif
1617  if (err != CMSG_OK) {
1618  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1619  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1620  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1621  else throw(cMsgException("Error"));
1622  }
1623 
1624 }
1625 
1626 
1627 //-------------------------------------------------------------------
1628 
1629 
1641 void cMsgMessage::add(const string &name, const cMsgMessage* *msg, int len) {
1642  if (msg == NULL) throw (cMsgException("msg arg is null"));
1643  if (len < 1) throw (cMsgException("cmsg message array len < 1"));
1644 
1645 #ifdef linux
1646  const void *msgs[len];
1647 #else
1648  const void **msgs = (const void **)malloc(len*sizeof(void *));
1649  if (msgs == NULL) throw(cMsgException("No memory available"));
1650 #endif
1651 
1652  for (int i=0; i<len; i++) {
1653  msgs[i] = msg[i]->myMsgPointer;
1654  }
1655 
1656  int err = cMsgAddMessageArray(myMsgPointer, name.c_str(), msgs, len);
1657 #ifndef linux
1658  free(msgs);
1659 #endif
1660  if (err != CMSG_OK) {
1661  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1662  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1663  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1664  else throw(cMsgException("Error"));
1665  }
1666 
1667 }
1668 
1669 
1670 //-------------------------------------------------------------------
1671 
1672 
1683 void cMsgMessage::add(const string &name, const vector<cMsgMessage*> &msgPVec) {
1684  if (msgPVec.size() < 1) throw(cMsgException("Zero length vector"));
1685 #ifdef linux
1686  const void *msgs[msgPVec.size()];
1687 #else
1688  const void **msgs = (const void **)malloc(msgPVec.size()*sizeof(void *));
1689  if (msgs == NULL) throw(cMsgException("No memory available"));
1690 #endif
1691 
1692  for (vector<cMsgMessage*>::size_type i=0; i < msgPVec.size(); i++) {
1693  msgs[i] = msgPVec[i]->myMsgPointer;
1694  }
1695 
1696  int err = cMsgAddMessageArray(myMsgPointer, name.c_str(), msgs, msgPVec.size());
1697 #ifndef linux
1698  free(msgs);
1699 #endif
1700  if (err != CMSG_OK) {
1701  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1702  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1703  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1704  else throw(cMsgException("Error"));
1705  }
1706 
1707 }
1708 
1709 
1710 //-------------------------------------------------------------------
1711 
1712 
1723 void cMsgMessage::add(const string &name, const vector<cMsgMessage> &msgVec) {
1724  if (msgVec.size() < 1) throw(cMsgException("Zero length vector"));
1725 #ifdef linux
1726  const void *msgs[msgVec.size()];
1727 #else
1728  const void **msgs = (const void **)malloc(msgVec.size()*sizeof(void *));
1729  if (msgs == NULL) throw(cMsgException("No memory available"));
1730 #endif
1731 
1732  for (vector<cMsgMessage>::size_type i=0; i < msgVec.size(); i++) {
1733  msgs[i] = msgVec[i].myMsgPointer;
1734  }
1735 
1736  int err = cMsgAddMessageArray(myMsgPointer, name.c_str(), msgs, msgVec.size());
1737 #ifndef linux
1738  free(msgs);
1739 #endif
1740  if (err != CMSG_OK) {
1741  if (err == CMSG_BAD_FORMAT) throw(cMsgException("Improper name"));
1742  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1743  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1744  else throw(cMsgException("Error"));
1745  }
1746 
1747 }
1748 
1749 
1750 //-------------------------------------------------------------------
1751 
1752 
1763 void cMsgMessage::add(const string &name, const vector<cMsgMessage*> *msgPVec) {
1764  add(name,*msgPVec);
1765 }
1766 
1767 
1768 //-------------------------------------------------------------------
1769 
1770 
1781 void cMsgMessage::add(const string &name, const vector<cMsgMessage> *msgVec) {
1782  add(name,*msgVec);
1783 }
1784 
1785 
1786 //-------------------------------------------------------------------
1787 // REALS
1788 //-------------------------------------------------------------------
1789 
1800 void cMsgMessage::add(const string &name, float val) {
1801  int err = cMsgAddFloat(myMsgPointer, name.c_str(), val);
1802  if (err != CMSG_OK) {
1803  if (err == CMSG_BAD_FORMAT ||
1804  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
1805  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1806  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1807  else throw(cMsgException("Error"));
1808  }
1809 }
1810 
1811 //-------------------------------------------------------------------
1812 
1823 void cMsgMessage::add(const string &name, double val) {
1824  int err = cMsgAddDouble(myMsgPointer, name.c_str(), val);
1825  if (err != CMSG_OK) {
1826  if (err == CMSG_BAD_FORMAT ||
1827  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
1828  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1829  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1830  else throw(cMsgException("Error"));
1831  }
1832 }
1833 
1834 //-------------------------------------------------------------------
1835 // REAL ARRAYS
1836 //-------------------------------------------------------------------
1837 
1849 void cMsgMessage::add(const string &name, const float *vals, int len) {
1850  int err = cMsgAddFloatArray(myMsgPointer, name.c_str(), vals, len);
1851  if (err != CMSG_OK) {
1852  if (err == CMSG_BAD_FORMAT ||
1853  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
1854  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1855  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1856  else throw(cMsgException("Error"));
1857  }
1858 }
1859 
1860 //-------------------------------------------------------------------
1861 
1872 void cMsgMessage::add(const string &name, const vector<float> &vals) {
1873  int err = cMsgAddFloatArray(myMsgPointer, name.c_str(), &vals[0], vals.size());
1874  if (err != CMSG_OK) {
1875  if (err == CMSG_BAD_FORMAT ||
1876  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
1877  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1878  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1879  else throw(cMsgException("Error"));
1880  }
1881 }
1882 
1883 //-------------------------------------------------------------------
1884 
1895 void cMsgMessage::add(const string &name, const vector<float> *vals) {
1896  add(name,*vals);
1897 }
1898 
1899 //-------------------------------------------------------------------
1900 
1912 void cMsgMessage::add(const string &name, const double *vals, int len) {
1913  int err = cMsgAddDoubleArray(myMsgPointer, name.c_str(), vals, len);
1914  if (err != CMSG_OK) {
1915  if (err == CMSG_BAD_FORMAT ||
1916  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
1917  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1918  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1919  else throw(cMsgException("Error"));
1920  }
1921 }
1922 
1923 //-------------------------------------------------------------------
1924 
1935 void cMsgMessage::add(const string &name, const vector<double> &vals) {
1936  int err = cMsgAddDoubleArray(myMsgPointer, name.c_str(), &vals[0], vals.size());
1937  if (err != CMSG_OK) {
1938  if (err == CMSG_BAD_FORMAT ||
1939  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
1940  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1941  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1942  else throw(cMsgException("Error"));
1943  }
1944 }
1945 
1946 //-------------------------------------------------------------------
1947 
1958 void cMsgMessage::add(const string &name, const vector<double> *vals) {
1959  add(name,*vals);
1960 }
1961 
1962 //-------------------------------------------------------------------
1963 // INTS
1964 //-------------------------------------------------------------------
1965 
1976 void cMsgMessage::add(const string &name, int8_t val) {
1977  int err = cMsgAddInt8(myMsgPointer, name.c_str(), val);
1978  if (err != CMSG_OK) {
1979  if (err == CMSG_BAD_FORMAT ||
1980  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
1981  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
1982  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
1983  else throw(cMsgException("Error"));
1984  }
1985 }
1986 
1987 //-------------------------------------------------------------------
1988 
1999 void cMsgMessage::add(const string &name, int16_t val) {
2000  int err = cMsgAddInt16(myMsgPointer, name.c_str(), val);
2001  if (err != CMSG_OK) {
2002  if (err == CMSG_BAD_FORMAT ||
2003  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2004  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2005  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2006  else throw(cMsgException("Error"));
2007  }
2008 }
2009 
2010 //-------------------------------------------------------------------
2011 
2022 void cMsgMessage::add(const string &name, int32_t val) {
2023  int err = cMsgAddInt32(myMsgPointer, name.c_str(), val);
2024  if (err != CMSG_OK) {
2025  if (err == CMSG_BAD_FORMAT ||
2026  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2027  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2028  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2029  else throw(cMsgException("Error"));
2030  }
2031 }
2032 
2033 //-------------------------------------------------------------------
2034 
2045 void cMsgMessage::add(const string &name, int64_t val) {
2046  int err = cMsgAddInt64(myMsgPointer, name.c_str(), val);
2047  if (err != CMSG_OK) {
2048  if (err == CMSG_BAD_FORMAT ||
2049  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2050  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2051  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2052  else throw(cMsgException("Error"));
2053  }
2054 }
2055 
2056 //-------------------------------------------------------------------
2057 
2068 void cMsgMessage::add(const string &name, uint8_t val) {
2069  int err = cMsgAddUint8(myMsgPointer, name.c_str(), val);
2070  if (err != CMSG_OK) {
2071  if (err == CMSG_BAD_FORMAT ||
2072  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2073  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2074  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2075  else throw(cMsgException("Error"));
2076  }
2077 }
2078 
2079 //-------------------------------------------------------------------
2080 
2091 void cMsgMessage::add(const string &name, uint16_t val) {
2092  int err = cMsgAddUint16(myMsgPointer, name.c_str(), val);
2093  if (err != CMSG_OK) {
2094  if (err == CMSG_BAD_FORMAT ||
2095  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2096  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2097  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2098  else throw(cMsgException("Error"));
2099  }
2100 }
2101 
2102 //-------------------------------------------------------------------
2103 
2114 void cMsgMessage::add(const string &name, uint32_t val) {
2115  int err = cMsgAddUint32(myMsgPointer, name.c_str(), val);
2116  if (err != CMSG_OK) {
2117  if (err == CMSG_BAD_FORMAT ||
2118  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2119  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2120  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2121  else throw(cMsgException("Error"));
2122  }
2123 }
2124 
2125 //-------------------------------------------------------------------
2126 
2137 void cMsgMessage::add(const string &name, uint64_t val) {
2138  int err = cMsgAddUint64(myMsgPointer, name.c_str(), val);
2139  if (err != CMSG_OK) {
2140  if (err == CMSG_BAD_FORMAT ||
2141  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2142  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2143  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2144  else throw(cMsgException("Error"));
2145  }
2146 }
2147 
2148 //-------------------------------------------------------------------
2149 // INT ARRAYS
2150 //-------------------------------------------------------------------
2151 
2163 void cMsgMessage::add(const string &name, const int8_t *vals, int len) {
2164  int err = cMsgAddInt8Array(myMsgPointer, name.c_str(), vals, len);
2165  if (err != CMSG_OK) {
2166  if (err == CMSG_BAD_FORMAT ||
2167  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2168  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2169  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2170  else throw(cMsgException("Error"));
2171  }
2172 }
2173 
2174 //-------------------------------------------------------------------
2175 
2186 void cMsgMessage::add(const string &name, const vector<int8_t> &vals) {
2187 
2188  // Can transform vector into array since STL standard mandates continguous
2189  // memory for storage of vector data (ie it's a standard C++ technique).
2190  int err = cMsgAddInt8Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2191  if (err != CMSG_OK) {
2192  if (err == CMSG_BAD_FORMAT ||
2193  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2194  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2195  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2196  else throw(cMsgException("Error"));
2197  }
2198 }
2199 
2200 //-------------------------------------------------------------------
2201 
2212 void cMsgMessage::add(const string &name, const vector<int8_t> *vals) {
2213  add(name,*vals);
2214 }
2215 
2216 //-------------------------------------------------------------------
2217 
2229 void cMsgMessage::add(const string &name, const int16_t *vals, int len) {
2230  int err = cMsgAddInt16Array(myMsgPointer, name.c_str(), vals, len);
2231  if (err != CMSG_OK) {
2232  if (err == CMSG_BAD_FORMAT ||
2233  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2234  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2235  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2236  else throw(cMsgException("Error"));
2237  }
2238 }
2239 
2240 //-------------------------------------------------------------------
2241 
2252 void cMsgMessage::add(const string &name, const vector<int16_t> &vals) {
2253  // Can transform vector into array since STL standard mandates continguous
2254  // memory for storage of vector data (ie it's a standard C++ technique).
2255  int err = cMsgAddInt16Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2256  if (err != CMSG_OK) {
2257  if (err == CMSG_BAD_FORMAT ||
2258  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2259  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2260  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2261  else throw(cMsgException("Error"));
2262  }
2263 }
2264 
2265 //-------------------------------------------------------------------
2266 
2277 void cMsgMessage::add(const string &name, const vector<int16_t> *vals) {
2278  add(name,*vals);
2279 }
2280 
2281 //-------------------------------------------------------------------
2282 
2294 void cMsgMessage::add(const string &name, const int32_t *vals, int len) {
2295  int err = cMsgAddInt32Array(myMsgPointer, name.c_str(), vals, len);
2296  if (err != CMSG_OK) {
2297  if (err == CMSG_BAD_FORMAT ||
2298  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2299  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2300  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2301  else throw(cMsgException("Error"));
2302  }
2303 }
2304 
2305 //-------------------------------------------------------------------
2306 
2317 void cMsgMessage::add(const string &name, const vector<int32_t> &vals) {
2318 
2319  // Can transform vector into array since STL standard mandates continguous
2320  // memory for storage of vector data (ie it's a standard C++ technique).
2321  int err = cMsgAddInt32Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2322  if (err != CMSG_OK) {
2323  if (err == CMSG_BAD_FORMAT ||
2324  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2325  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2326  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2327  else throw(cMsgException("Error"));
2328  }
2329 }
2330 
2331 //-------------------------------------------------------------------
2332 
2343 void cMsgMessage::add(const string &name, const vector<int32_t> *vals) {
2344  add(name,*vals);
2345 }
2346 
2347 //-------------------------------------------------------------------
2348 
2360 void cMsgMessage::add(const string &name, const int64_t *vals, int len) {
2361  int err = cMsgAddInt64Array(myMsgPointer, name.c_str(), vals, len);
2362  if (err != CMSG_OK) {
2363  if (err == CMSG_BAD_FORMAT ||
2364  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2365  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2366  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2367  else throw(cMsgException("Error"));
2368  }
2369 }
2370 
2371 //-------------------------------------------------------------------
2372 
2383 void cMsgMessage::add(const string &name, const vector<int64_t> &vals) {
2384 
2385  // Can transform vector into array since STL standard mandates continguous
2386  // memory for storage of vector data (ie it's a standard C++ technique).
2387  int err = cMsgAddInt64Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2388  if (err != CMSG_OK) {
2389  if (err == CMSG_BAD_FORMAT ||
2390  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2391  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2392  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2393  else throw(cMsgException("Error"));
2394  }
2395 }
2396 
2397 //-------------------------------------------------------------------
2398 
2409 void cMsgMessage::add(const string &name, const vector<int64_t> *vals) {
2410  add(name,*vals);
2411 }
2412 
2413 //-------------------------------------------------------------------
2414 //-------------------------------------------------------------------
2415 
2427 void cMsgMessage::add(const string &name, const uint8_t *vals, int len) {
2428  int err = cMsgAddUint8Array(myMsgPointer, name.c_str(), vals, len);
2429  if (err != CMSG_OK) {
2430  if (err == CMSG_BAD_FORMAT ||
2431  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2432  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2433  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2434  else throw(cMsgException("Error"));
2435  }
2436 }
2437 
2438 //-------------------------------------------------------------------
2439 
2450 void cMsgMessage::add(const string &name, const vector<uint8_t> &vals) {
2451 
2452  // Can transform vector into array since STL standard mandates continguous
2453  // memory for storage of vector data (ie it's a standard C++ technique).
2454  int err = cMsgAddUint8Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2455  if (err != CMSG_OK) {
2456  if (err == CMSG_BAD_FORMAT ||
2457  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2458  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2459  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2460  else throw(cMsgException("Error"));
2461  }
2462 }
2463 
2464 //-------------------------------------------------------------------
2465 
2476 void cMsgMessage::add(const string &name, const vector<uint8_t> *vals) {
2477  add(name,*vals);
2478 }
2479 
2480 //-------------------------------------------------------------------
2481 
2493 void cMsgMessage::add(const string &name, const uint16_t *vals, int len) {
2494  int err = cMsgAddUint16Array(myMsgPointer, name.c_str(), vals, len);
2495  if (err != CMSG_OK) {
2496  if (err == CMSG_BAD_FORMAT ||
2497  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2498  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2499  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2500  else throw(cMsgException("Error"));
2501  }
2502 }
2503 
2504 //-------------------------------------------------------------------
2505 
2516 void cMsgMessage::add(const string &name, const vector<uint16_t> &vals) {
2517 
2518  // Can transform vector into array since STL standard mandates continguous
2519  // memory for storage of vector data (ie it's a standard C++ technique).
2520  int err = cMsgAddUint16Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2521  if (err != CMSG_OK) {
2522  if (err == CMSG_BAD_FORMAT ||
2523  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2524  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2525  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2526  else throw(cMsgException("Error"));
2527  }
2528 }
2529 
2530 //-------------------------------------------------------------------
2531 
2542 void cMsgMessage::add(const string &name, const vector<uint16_t> *vals) {
2543  add(name,*vals);
2544 }
2545 
2546 //-------------------------------------------------------------------
2547 
2559 void cMsgMessage::add(const string &name, const uint32_t *vals, int len) {
2560  int err = cMsgAddUint32Array(myMsgPointer, name.c_str(), vals, len);
2561  if (err != CMSG_OK) {
2562  if (err == CMSG_BAD_FORMAT ||
2563  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2564  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2565  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2566  else throw(cMsgException("Error"));
2567  }
2568 }
2569 
2570 //-------------------------------------------------------------------
2571 
2582 void cMsgMessage::add(const string &name, const vector<uint32_t> &vals) {
2583 
2584  // Can transform vector into array since STL standard mandates continguous
2585  // memory for storage of vector data (ie it's a standard C++ technique).
2586  int err = cMsgAddUint32Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2587  if (err != CMSG_OK) {
2588  if (err == CMSG_BAD_FORMAT ||
2589  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2590  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2591  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2592  else throw(cMsgException("Error"));
2593  }
2594 }
2595 
2596 //-------------------------------------------------------------------
2597 
2608 void cMsgMessage::add(const string &name, const vector<uint32_t> *vals) {
2609  add(name,*vals);
2610 }
2611 
2612 //-------------------------------------------------------------------
2613 
2625 void cMsgMessage::add(const string &name, const uint64_t *vals, int len) {
2626  int err = cMsgAddUint64Array(myMsgPointer, name.c_str(), vals, len);
2627  if (err != CMSG_OK) {
2628  if (err == CMSG_BAD_FORMAT ||
2629  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name or vals is null"));
2630  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2631  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2632  else throw(cMsgException("Error"));
2633  }
2634 }
2635 
2636 //-------------------------------------------------------------------
2637 
2648 void cMsgMessage::add(const string &name, const vector<uint64_t> &vals) {
2649 
2650  // Can transform vector into array since STL standard mandates continguous
2651  // memory for storage of vector data (ie it's a standard C++ technique).
2652  int err = cMsgAddUint64Array(myMsgPointer, name.c_str(), &vals[0], vals.size());
2653  if (err != CMSG_OK) {
2654  if (err == CMSG_BAD_FORMAT ||
2655  err == CMSG_BAD_ARGUMENT) throw(cMsgException("Improper name"));
2656  else if (err == CMSG_ALREADY_EXISTS) throw(cMsgException("Name being used"));
2657  else if (err == CMSG_OUT_OF_MEMORY) throw(cMsgException("No memory available"));
2658  else throw(cMsgException("Error"));
2659  }
2660 }
2661 
2662 //-------------------------------------------------------------------
2663 
2674 void cMsgMessage::add(const string &name, const vector<uint64_t> *vals) {
2675  add(name,*vals);
2676 }
2677 
2678 //-------------------------------------------------------------------
2679 
2680 
2681 } // namespace cmsg
void * myMsgPointer
Pointer to C message structure.
Definition: cMsg.hxx:304
Class for wrapping cMsg message.
Definition: cMsg.hxx:79
Exception includes description and return code.
Definition: cMsg.hxx:53