QField.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:2k
源码类别:

DVD

开发平台:

C/C++

  1. #include <assert.h>
  2. #include "QField.h"
  3. QField NewQField()
  4. {
  5.    QField self;
  6.    self.Init = QFieldInit;
  7.    self.Release = QFieldRelease;
  8.    self.name = NewQString();
  9.    self.value = NewQString();
  10.    return self;
  11. }
  12. QField *MallocQField()
  13. {
  14.    QField *self = (QField *)KB_OSPMalloc(sizeof(QField));
  15.    if(!self) return NULL;
  16.     self->Init = QFieldInit;
  17.    self->Release = QFieldRelease;
  18.    self->name = NewQString();
  19.    self->value = NewQString();
  20.    return self;
  21. }
  22. void QFieldInit(QField *self, char *name ,char *value)
  23. {
  24.    assert(self);
  25. //   assert(name);
  26.    if(!name) return ;   
  27.    self->name.ReSet(&self->name,name);
  28.    self->value.ReSet(&self->value,value);
  29. }
  30. void QFieldRelease(QField *self)
  31. {
  32.    assert(self);
  33.    self->name.Release(&self->name);
  34.    self->value.Release(&self->value);   
  35. }
  36. QFieldList NewQFieldList()
  37. {
  38.    QFieldList self;
  39.    self.Find = QFieldListFind;
  40.    self.Release = QFieldListRelease;
  41.    self.m_listField = NewQList();
  42.    return self;
  43. }
  44. QFieldList *MallocQFieldList()
  45. {
  46.    QFieldList *self = (QFieldList *)KB_OSPMalloc(sizeof(QFieldList));
  47.    if(!self) return NULL;
  48.    self->Find = QFieldListFind;
  49.    self->Release = QFieldListRelease;
  50.    
  51.    self->m_listField = NewQList();
  52.    return self;
  53. }
  54. char   *QFieldListFind (QFieldList *self , char *name)
  55. {
  56.    List *pTemp;
  57.    List *p;
  58.    QField *field;
  59.    assert(self);
  60.    if(!name) return NULL;
  61.    if (self->m_listField.m_pHead == NULL)
  62.       return NULL;
  63.    p = self->m_listField.m_pTail;
  64.    while (p)
  65.    {
  66.       pTemp = p->pPrev;
  67.       field = (QField *)p->pData;
  68.       if(field->name.Equal(&field->name,name))
  69.       {
  70.          return field->value.m_dataBuff;
  71.       }
  72.       p = pTemp;
  73.    }
  74.    return NULL;
  75. }
  76. void   QFieldListRelease(QFieldList *self)
  77. {
  78.    List *pTemp;
  79.    List *p;
  80.    assert(self);
  81.    if (self->m_listField.m_pHead == NULL)
  82.       return;
  83.    p = self->m_listField.m_pTail;
  84.    while (p)
  85.    {
  86.       pTemp = p->pPrev;   
  87.       ((QField *)(p->pData))->Release(((QField *)(p->pData)));
  88.       KB_OSPFree(p->pData);
  89.       p = pTemp;
  90.    }
  91.    self->m_listField.Clear(&self->m_listField);
  92. }