1: 
   2: 
   3: /**********************
   4: *                     *
   5: *  COMPILER INCLUDES  *
   6: *                     *
   7: **********************/
   8: 
   9: 
  10: #include <cassert> 
  11: 
  12: 
  13: /*********************
  14: *                    *
  15: *  PROJECT INCLUDES  *
  16: *                    *
  17: *********************/
  18: 
  19: 
  20: #include "am.h" 
  21: #include "labellist.h" 
  22: #include "wwwi/string.h" 
  23: 
  24: 
  25: using WWWI::StringConcat;
  26: using std::strchr;
  27: using std::strlen;
  28: 
  29: 
  30: /***************************
  31: *                          *
  32: *  LABELLIST CONSTRUCTORS  *
  33: *                          *
  34: ***************************/
  35: 
  36: 
  37: LabelList::LabelList() {
  38:   AMCTOR(LabelList);
  39: }
  40: 
  41: 
  42: LabelList::LabelList(const char *i_strName) {
  43:   const char *pcPos = i_strName;
  44:   const char *pcDot;
  45:   
  46:   AMCTOR(LabelList);
  47:   while(NULL!=(pcDot = strchr(pcPos,'.'))) {
  48:     this->push_back(Label(pcDot-pcPos,pcPos));
  49:     pcPos = pcDot + 1;
  50:   }
  51:   if (*pcPos!=0) {
  52:     this->push_back(Label(strlen(pcPos),pcPos));
  53:   }
  54: }
  55: 
  56: 
  57: LabelList::LabelList(const unsigned char *ci_ucpLabels) {
  58:   unsigned short us;
  59:   AMCTOR(LabelList);
  60:   while(*ci_ucpLabels!=0) {
  61:     us = *ci_ucpLabels++;
  62:     this->push_back(Label(us,(const char*)ci_ucpLabels));
  63:     ci_ucpLabels += us;
  64:   }
  65: }
  66: 
  67: 
  68: LabelList::LabelList(const LabelList &ci_llr) {
  69:   AMCTOR(LabelList);
  70:   (*this) = ci_llr;
  71: }
  72: 
  73: 
  74: /***********************
  75: *                      *
  76: *  METHOD GETRDLENGTH  *
  77: *                      *
  78: ***********************/
  79: 
  80: 
  81: unsigned short LabelList::GetRDLength() const {
  82:   LabelList::const_iterator it;
  83:   unsigned usLen = 1;
  84: 
  85:   // Each item has a byte up front with the size, so it's size+1, plus one 
  86:   // for the trailing \0.
  87:   for(it=this->begin();it!=this->end();++it) {
  88:     usLen += ((*it).GetLength() + 1);
  89:   }
  90:   return usLen;
  91: }
  92: 
  93: 
  94: /*****************
  95: *                *
  96: *  METHOD TORAW  *
  97: *                *
  98: *****************/
  99: 
 100: 
 101: unsigned short LabelList::ToRaw(unsigned char *i_ucpData) const {
 102:   LabelList::const_iterator lbi;
 103:   unsigned short usLength = 1;
 104:  
 105:   for(lbi=this->begin();lbi!=this->end();++lbi) {
 106:     *i_ucpData++ = (unsigned char)((*lbi).GetLength());
 107:     memcpy(i_ucpData,(*lbi).GetString(),(*lbi).GetLength());
 108:     i_ucpData += (*lbi).GetLength();
 109:     usLength += ((*lbi).GetLength() + 1);
 110:   }
 111:   *i_ucpData = 0;
 112:   assert(usLength<256);
 113:   return usLength;
 114: }
 115: 
 116: 
 117: /*********************
 118: *                    *
 119: *  METHODS TOSTRING  *
 120: *                    *
 121: *********************/
 122: 
 123: 
 124: void LabelList::ToString(char *o_strOut, size_t i_szOut) const {
 125:   assert(o_strOut!=NULL);
 126:   assert(i_szOut>0);
 127: 
 128:   LabelList::const_iterator lbi;
 129: 
 130:   o_strOut[0] = 0;
 131:   for(lbi=this->begin();lbi!=this->end();++lbi) {
 132:     if (lbi!=this->begin()) StringConcat(o_strOut,i_szOut,".");
 133:     StringConcat(o_strOut,i_szOut,(*lbi).GetString());
 134:   }
 135: }
 136: 
 137: 
 138: char *LabelList::ToString() const {
 139:   unsigned short us = this->GetRDLength();
 140:   char *strOut = new char[us];
 141: 
 142:   this->ToString(strOut,us);
 143:   return strOut;
 144: }
 145: 
 146: 
 147: /*************************
 148: *                        *
 149: *  LABELLIST DESTRUCTOR  *
 150: *                        *
 151: *************************/
 152: 
 153: 
 154: LabelList::~LabelList() {
 155:   AMDTOR(LabelList);
 156: }
 157: 
 158: 
 159: /****************
 160: *               *
 161: *  OPERATOR <<  *
 162: *               *
 163: ****************/
 164: 
 165: 
 166: ostream& operator<<(ostream& io_smr, const LabelList &ci_llr) {
 167:   io_smr << &ci_llr;  
 168:   return io_smr;      
 169: }
 170: 
 171: 
 172: ostream& operator<<(ostream& io_smr, LabelListConstPtr ci_llp) {
 173:   LabelList::const_iterator lbi;
 174: 
 175:   if (ci_llp->size()==0) {
 176:     io_smr << ".";
 177:     return io_smr;
 178:   }
 179: 
 180:   for(lbi=ci_llp->begin();lbi!=ci_llp->end();++lbi) {
 181:     io_smr << (*lbi) << ".";
 182:   }
 183:   return io_smr;
 184: }
 185: 
 186: 
 187: