⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_par_reader.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return UMC_OK;
  }
  return UMC_WRN_TYPE_MISMATCH;
}

// returns UMC_ERR_NOT_FOUND if no record,
// UMC_WRN_TYPE_MISMATCH if type mismatch or the record has arguments
// else return UMC_OK with success
Status ParamList::getValue(const vm_char* name)
{
  Parameter *rec = findParam(name);
  if(rec == 0)
    return UMC_ERR_NOT_FOUND;
  if(rec->m_info == 0) {
    if(rec->m_nargs == 0)
      return UMC_OK;
  } else if(rec->m_info->argType == argOpt)
    return UMC_OK;
  return UMC_WRN_TYPE_MISMATCH;
}


// adds group of parameters descriptions
// see top of the file for descr
// group name is supposed to be codec class name and used now only for information
Status ParamList::addOptionInfo(const vm_char* group_name, const OptionInfo* descr)
{
  const OptionInfo* rec;
  OptionInfoGroup* entry;
  Ipp32s count;
  const vm_char* ptr;

  if(descr == 0 || descr->name == 0 /*|| descr->name[0] == 0*/)
    return UMC_ERR_NULL_PTR; // no descriptions or empty

  for(entry = m_listOptionInfo; entry != 0; entry = entry->next)
    if( 0 == vm_string_strcmp(group_name, entry->groupName))
      return UMC_OK; // already exist

  // count entries
  // can check input descriptions here
  // and return UMC_ERR_INVALID_STREAM; on error
  for(rec = descr, count = 0;
    rec->name != 0 /*&& rec->name[0] != 0*/; rec++, count++)
  {
    Ipp32s i;
    // check if name exists
    const OptionInfo* old = findOptionInfo(rec->name);
    if(old != 0)
      return UMC_ERR_INVALID_STREAM; // duplicates
    if(rec->synonym != 0) {
      if(rec->synonym[0] == 0)
        return UMC_ERR_INVALID_STREAM;
      if(0 == findOptionInfo(rec->synonym)) {
        Ipp32s found = 0;
        for(i=0; descr[i].name != 0 /*&& descr[i].name[0] != 0*/; i++) {
          if(0 == vm_string_strcmp(descr[i].name, rec->synonym)) {
            found = 1;
            break;
          }
        }
        if(found == 0) // synonym name is undefined
          return UMC_ERR_INVALID_STREAM;
      }
      continue; // to the next line
    } else {
      for(i=0; i<count; i++)
        if(0 == vm_string_strcmp(descr[i].name, rec->name))
          return UMC_ERR_INVALID_STREAM; // repeated name
    }
    ptr = rec->limits;
    // check description
    if(rec->checkType == checkMin || rec->checkType == checkMax || rec->checkType == checkMinMax) {
      if(rec->limits == 0)
        return UMC_ERR_INVALID_STREAM;
      if(rec->checkType == checkMinMax) {
        ptr += vm_string_strcspn(rec->limits, DELIMITER);
        ptr += vm_string_strspn(ptr, DELIMITER);
      }
      if(argInt == rec->argType) {
        Ipp32s imin, imax;
        if(1 != vm_string_sscanf(rec->limits, VM_STRING("%d"), &imin))
          return UMC_ERR_INVALID_STREAM;
        if(rec->checkType == checkMinMax) {
          if (1 != vm_string_sscanf(ptr, VM_STRING("%d"), &imax) || imin > imax)
            return UMC_ERR_INVALID_STREAM;
        }
      } else if(argFlt == rec->argType) {
        Ipp64f dmin, dmax;
        if(1 != vm_string_sscanf(rec->limits, VM_STRING("%lf"), &dmin))
          return UMC_ERR_INVALID_STREAM;
        if(rec->checkType == checkMinMax) {
          if (1 != vm_string_sscanf(ptr, VM_STRING("%lf"), &dmax) || dmin > dmax)
            return UMC_ERR_INVALID_STREAM;
        }
      } else if(argOther != rec->argType)
        return UMC_ERR_INVALID_STREAM;

    } else if(rec->checkType == checkSet) {
      if(rec->limits == 0 || rec->limits[0] == 0)
        return UMC_ERR_INVALID_STREAM; // must be at least 1 entry
      do {
        if(argInt == rec->argType) {
          Ipp32s ival;
          if(1 != vm_string_sscanf(ptr,VM_STRING("%d"),&ival))
            return UMC_ERR_INVALID_STREAM;
        } else if(argFlt == rec->argType) {
          Ipp64f dval;
          if(1 != vm_string_sscanf(ptr,VM_STRING("%lf"),&dval))
            return UMC_ERR_INVALID_STREAM;
        } else
          break; //don't check not numbers
        ptr += vm_string_strspn(ptr, DELIMITER);
        ptr++; // next element or 0 in the end
      } while(*ptr != 0);
    } else if(rec->checkType != checkNone)
      return UMC_ERR_INVALID_STREAM;
  } // end of description group checking

  entry = new OptionInfoGroup;
  if(entry == 0)
    return UMC_ERR_ALLOC;
  entry->count = count;
  entry->entry = descr;
  entry->groupName = group_name;
  // add to the beginning of the list
  entry->next = m_listOptionInfo;
  m_listOptionInfo = entry;
  m_numOptionInfo += count;

  // option could have been read before - update
  Parameter* ppar = m_plist;
  while(ppar != 0) {
    const OptionInfo *pInfo;
    if(ppar->m_info == 0) {
      pInfo = findOptionInfo(ppar->m_name);
      if(pInfo != 0 && ppar->m_nargs == pInfo->numArgs) {
        Ipp32s i;
        for(i=0; i<ppar->m_nargs; i++) {
          if(UMC_OK != ppar->checkValue(ppar->getValue(i)))
            break;
        }
        if(i == ppar->m_nargs) {
          ppar->m_name = pInfo->name;
          ppar->m_info = pInfo;
        }
      }
    }
    ppar = ppar->m_next;
  }

  return UMC_OK;
}

// return description by index
// used for access to accumulated descriptions
const ParamList::OptionInfo* ParamList::getOptionInfo(Ipp32s index)
{
  OptionInfoGroup* dentry = m_listOptionInfo;
  Ipp32s numrec = m_numOptionInfo;
  if(index >= m_numOptionInfo)
    return 0;

  while(dentry->count <= index) {
    index -= dentry->count;
    numrec -= dentry->count; // to verify
    dentry = dentry->next;
    if(dentry == 0 || numrec <= 0)
      return 0;
  }

  return dentry->entry + index;
}


// returns text description for parameter name
const vm_char* ParamList::helpParam(const vm_char* name)
{
  const vm_char* text;

  const OptionInfo* info = findOptionInfo(name);
  if(info == 0)
    text = VM_STRING("");
  else
    text = info->comment;

  return text;
}

Status ParamList::dumpHelp(vm_file* out)
{
  OptionInfoGroup  *dentry = m_listOptionInfo;
  const OptionInfo *entry;

  if(out == 0)
    return UMC_ERR_NULL_PTR;

  while(dentry != 0) {
    vm_string_fprintf(out, VM_STRING("[%.80s]\n"),
      (dentry->groupName!=0)?dentry->groupName:VM_STRING(" "));
    for( entry = dentry->entry; entry->name != 0 /*&& entry->name[0] != 0*/; entry++) {
      if(entry->name[0] != 0)
        vm_string_fprintf(out, VM_STRING("-%-11s"), entry->name);
      else // possible empty name, say for input file
        vm_string_fprintf(out, VM_STRING("%12s"), VM_STRING("[no prefix]"));
      if(entry->synonym) {
        vm_string_fprintf(out, VM_STRING(" same as -%s\n"), entry->synonym);
        continue;
      }
      if(entry->numArgs > 1)
        vm_string_fprintf(out, VM_STRING(" (%d x "), entry->numArgs);
      else if(entry->numArgs == 1)
        vm_string_fprintf(out, VM_STRING(" ("));
      if(entry->numArgs > 0)
        vm_string_fprintf(out, VM_STRING("%s)"),
         (entry->argType == argInt)?VM_STRING("integer") :
        ((entry->argType == argFlt)?VM_STRING("Ipp32f"  ) :
        ((entry->argType == argStr)?VM_STRING("str"):VM_STRING("unknown"))));
      if(entry->comment)
        vm_string_fprintf(out, VM_STRING(" %s"), entry->comment);
      vm_string_fprintf(out, VM_STRING("\n"));
    }
    dentry = dentry->next;
  }

  return UMC_OK;
}
/*! \fn Status ParamList::dumpParams(FILE* out)
Prints information about all parameters read with arguments to stream \a out
\param out stream pointer
\return UMC_OK on success
*/
Status ParamList::dumpParams(vm_file* out)
{
  if(out == 0)
    return UMC_ERR_NULL_PTR;

  Parameter* ppar = m_plist;
  while(ppar != 0) {
    Ipp32s i;
    vm_string_fprintf(out, VM_STRING("%11s "), ppar->m_name);
    for(i=0; i<ppar->m_nargs; i++) {
      if(i>0)
        vm_string_fprintf(out, VM_STRING("; "));
      vm_string_fprintf(out, VM_STRING("%s"), ppar->getValue(i));
    }
    const vm_char* helpstr = helpParam(ppar->m_name);
    if(vm_string_strlen(helpstr) > 0)
      vm_string_fprintf(out, VM_STRING("\t# %s"), helpParam(ppar->m_name));
    vm_string_fprintf(out, VM_STRING("\n"));
    ppar = ppar->m_next;
  }
  return UMC_OK;
}

ParamList::Parameter::~Parameter()
{
  ValueChain* ptr = m_values;
  while(ptr != 0) {
    ValueChain* todel = ptr;
    ptr = ptr->next;
    delete todel;
  }
}

Status ParamList::Parameter::appendValue(const vm_char* value)
{
  ValueChain* ptr = m_values;
  Ipp32s numcheck = 0;
  Status ret = UMC_OK;
  if(ptr != 0)
    for(numcheck=1; ptr->next != 0; ptr = ptr->next) {
      numcheck++;
    }
  //VM_ASSERT(numcheck == m_nargs);
  //VM_ASSERT(numcheck == m_nargs);
  //if(numcheck != m_nargs) {
  //  m_nargs = numcheck; // self fix
  //}
  if(m_info)
    ret = checkValue(value);
  if(m_nargs==0) {
    m_values = new ValueChain;
    ptr = m_values;
  } else {
    ptr->next = new ValueChain;
    ptr = ptr->next;
  }
  if(ptr == 0)
    return UMC_ERR_ALLOC;
  ptr->next = 0;
  ptr->svalue = value;
  m_nargs++;
  return ret;
}
const vm_char* ParamList::Parameter::getValue(Ipp32s index)
{
  ValueChain* ptr = m_values;
  if(index>=m_nargs)
    return 0;
  while(index>0) {
    if(ptr->next == 0)
      return 0;
    ptr = ptr->next;
    index--;
  }
  return ptr->svalue;
}

// check values according to description's rules
// return UMC_OK on success
// UMC_ERR_INVALID_STREAM otherwise
Status ParamList::Parameter::checkValue(const vm_char* value)
{
  Ipp32s res;

  if(m_info != 0)
  switch(m_info->checkType) {
    case checkMin:
    case checkMax:
    case checkMinMax:
      {
        const vm_char *limmin, *limmax;
        limmax = limmin = m_info->limits;
        if(m_info->checkType == checkMinMax) {
          limmax += vm_string_strcspn(limmin, DELIMITER);
          limmax += vm_string_strspn(limmax, DELIMITER);
        }
        switch(m_info->argType) {
          case argFlt:
            {
              Ipp64f dval, dmin, dmax;
              //dval = atof(value);
              res = vm_string_sscanf(value, VM_STRING("%lf"), &dval);
              if(res != 1) {
                goto check_error;
              }
              if(m_info->checkType != checkMax) {
                vm_string_sscanf(limmin, VM_STRING("%lf"), &dmin);
                if(dmin>dval) {
                  //*value = limmin;
                  goto check_error;
                }
              }
              if(m_info->checkType != checkMin) {
                vm_string_sscanf(limmax, VM_STRING("%lf"), &dmax);
                if(dmax<dval) {
                  //*value = limmax;
                  goto check_error;
                }
              }
            } break;
          case argInt:
            {
              Ipp32s ival, imin, imax;
              //ival = vm_string_atoi(value);
              res = vm_string_sscanf(value, VM_STRING("%d"), &ival);
              if(res != 1) {
                goto check_error;
              }
              if(m_info->checkType != checkMax) {
                vm_string_sscanf(limmin, VM_STRING("%d"), &imin);
                if(imin>ival) {
                  //*value = limmin;
                  goto check_error;
                }
              }
              if(m_info->checkType != checkMin) {
                vm_string_sscanf(limmax, VM_STRING("%d"), &imax);
                if(imax<ival) {
                  //*value = limmax;
                  goto check_error;
                }
              }
            } break;
          case argOther:
            break;
          default:
            goto check_error;
        }
      } break;
    case checkSet:
      {
        size_t len;
        const vm_char *wrd = m_info->limits;
        switch(m_info->argType) {
          case argStr:
            do {
              len = vm_string_strcspn(wrd, DELIMITER);
              if( 0 == vm_string_strncmp(value, wrd, len))
                break;
              wrd += len + vm_string_strspn(wrd+len, DELIMITER);
            } while(*wrd != 0);
            break;
          case argFlt:
            {
              Ipp64f dval;// = atof(value);
              if(1 != vm_string_sscanf(value, VM_STRING("%lf"), &dval))
                break;
              for(; *wrd != 0; ) {
                Ipp64f dchk; // = atof(wrd);
                vm_string_sscanf(wrd, VM_STRING("%lf"), &dchk);
                if(dchk == dval)
                  break;
                wrd += vm_string_strcspn(wrd, DELIMITER);
                wrd += vm_string_strspn(wrd, DELIMITER);
              }
            } break;
          case argInt:
            {
              Ipp32s ival; // = vm_string_atoi(value);
              if(1 != vm_string_sscanf(value, VM_STRING("%d"), &ival))
                break;
              for(; *wrd != 0; ) {
                Ipp32s ichk; // = vm_string_atoi(wrd);
                vm_string_sscanf(wrd, VM_STRING("%d"), &ichk);
                if(ichk == ival)
                  break;
                wrd += vm_string_strcspn(wrd, DELIMITER);
                wrd += vm_string_strspn(wrd, DELIMITER);
              }
            } break;
          case argOpt:
            break;
          default:
            goto check_error;
      }
        if(*wrd == 0)
          goto check_error;
      } break;
    case checkNone:
      break;
    default:
      goto check_error;
  }
  return UMC_OK;
check_error:
  return UMC_ERR_INVALID_STREAM;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -