Esempio n. 1
0
FIT_UINT16 Mesg::GetActiveSubFieldIndexByFieldIndex(const FIT_UINT16 fieldIndex) const
{
   if ((int) fieldIndex >= GetNumFields())
      return FIT_SUBFIELD_INDEX_MAIN_FIELD;

   for (int i = 0; i < (int) fields[fieldIndex].GetNumSubFields(); i++)
   {
      const Profile::SUBFIELD* subField = fields[fieldIndex].GetSubField(i);

      if (subField != FIT_NULL)
      {
         for (int j = 0; j < (int) subField->numMaps; j++)
         {
            const Field* refField = GetField(subField->maps[j].refFieldNum);

            if (refField != FIT_NULL)
            {
               FIT_FLOAT64 refValue = refField->GetFLOAT64Value(0, FIT_SUBFIELD_INDEX_MAIN_FIELD);
               refValue += ((refValue >= 0.0) ? (0.5) : (-0.5));
               if ((FIT_SINT32)refValue == subField->maps[j].refFieldValue)
                  return ((FIT_UINT16) i);
            }
         }
      }
   }

   return FIT_SUBFIELD_INDEX_MAIN_FIELD;
}
Esempio n. 2
0
YKSQLRowSPtr YKOracleTable::FetchRow()
{
	try {
		if (m_result->next() != ResultSet::END_OF_FETCH)
			return YKOracleRowSPtr(new YKOracleRow(m_result, GetNumFields()));
	} catch (SQLException& err) {
		YK_ExceptionThrow(YKDSException) << YKDSException::E_Row(YKOracle::GetErrorMessage(err));
	}

	return YK_NULL;
}
Esempio n. 3
0
kGUIDbQuery::kGUIDbQuery(kGUIDb *db,const char *query,...)
{
    int i;
    int nf;
    kGUIString fquery;
    const char *errormsg;
    va_list args;

    /* for performance analysis */
    db->IncNumQueries();

    va_start(args, query);
    fquery.AVSprintf(query,args);
    va_end(args);

    if(db->GetTrace())
        db->GetTrace()->ASprintf("->%s\n",fquery.GetString());

tryagain:
    ;
    mysql_query(db->GetConn(),fquery.GetString());

    m_res_set = mysql_store_result(db->GetConn());

    errormsg=mysql_error(db->GetConn());
    if(errormsg[0])
    {
        if(!strcmp(errormsg,"Lost connection to MySQL server during query"))
        {
            /* try to re-connect! */
            db->ReConnect();
            goto tryagain;
        }
        else if(!strcmp(errormsg,"Server shutdown in progress") || !strcmp(errormsg,"MySQL server has gone away"))
        {
            /* hmmm, not sure what to do here! */
            return;
        }
        else
            assert(false,errormsg);
    }

    assert(m_res_set!=0,"Error, no result set!");

    /* use a hash table for field->index conversion */
    m_fi.Init(8,sizeof(int));
    nf=GetNumFields();
    for(i=0; i<nf; ++i)
        m_fi.Add(GetFieldName(i),&i);
}
Esempio n. 4
0
  uint32_t
  Struct::GetSchemaCrc() const
  {
    uint32_t crc = 0;

    for ( uint32_t i = 0; i < GetNumFields(); ++i )
    {
      const StructField* field = ( *this ) [ i ];
      const uint32_t field_crc = field->m_ValueInfo.GetSchemaCrc();
      crc = Crc32WithSeed ( &field_crc, 4, crc );
      crc += i;
    }

    return crc;
  }
Esempio n. 5
0
  StructField*
  Struct::FindField ( uint32_t hash )
  {
    for ( uint32_t i = 0; i < GetNumFields(); i++ )
    {
      StructField* field = ( *this ) [i];

      if ( field->m_ValueInfo.GetNameHash() == hash )
      {
        return field;
      }
    }

    return 0;
  }
Esempio n. 6
0
YKSQLFieldListSPtr YKOracleTable::GetFields()
{
	return YKOracleFieldListSPtr(new YKOracleFieldList(m_result, GetNumFields()));
}
Esempio n. 7
0
DataFile::DataFile(string fname) {
  int count=0;
  unsigned short start, end;
  string var;

  f.open(fname.c_str());
  f.setf(ios::skipws);
  if ( !f ) {
    cout << "fileopen failed for file " << fname << endl << endl;
    exit(-1);
  } else {
    cout << "File " << fname << " successfully opened." << endl;
  }

  getline(f, data_str);
  end = 0;

  while (1) {
    start = end;
    while (data_str[start] == ' ') start++;
    end = data_str.find(",", start);
    count++;
    if (end >= 65535) {
      end = data_str.size();
      var = data_str.substr(start, end-start);
      names.push_back(var);
      break;
    } else {
      var = data_str.substr(start, end-start);
      names.push_back(var);
      end++;
    }
  }

  cout << "Done parsing names. Reading data ..." << endl;

  int row=0, column=0;
  char scratch[10];

  while (1) {
    column = 0;
    Data.push_back(*(new Row()));
    while (1) {
      Data[row].push_back(0.0);
      f >> Data[row][column];
      if (f.eof()) {
        Data.pop_back();
        break;
      }
      if (++column == count) break;
      else f >> scratch;
    }
    row++;
    if (f.eof()) break;
  }

  for (int i=0;i<GetNumFields();i++) {
    Max.push_back(0.0);
    Min.push_back(0.0);
  }

  for (int fld=0; fld<GetNumFields(); fld++) {
    Max[fld] = Data[0][fld];
    Min[fld] = Data[0][fld];
    for (int rec=1;rec<GetNumRecords();rec++) {
      if (Data[rec][fld] > Max[fld]) Max[fld] = Data[rec][fld];
      else if (Data[rec][fld] < Min[fld]) Min[fld] = Data[rec][fld];
    }
  }

  StartIdx = 0;
  EndIdx = GetNumRecords()-1;

  cout << endl << "Done Reading data ..." << endl;

}