コード例 #1
0
ファイル: PEPacket.cpp プロジェクト: carribus/firecell
bool PEPacket::AddField(const string& key, size_t elem_width, size_t elem_count, void* pDefaultValue)
{
  if ( FieldExists(key) )
    return false;

  Field f = { key, elem_width, elem_count, m_dataLen };
  size_t prevSize = m_dataLen, fieldSize = elem_width * elem_count;

  m_dataLen += elem_width * elem_count;
  if ( fieldSize )
  {
    if ( m_pDataBlock )
    {
      if ( !(m_pDataBlock = (char*)realloc( m_pDataBlock, m_dataLen )) )
        return false;
    }
    else
    {
      if ( !(m_pDataBlock = (char*)malloc(m_dataLen)) )
        return false;
    }
  }

  m_fields[key] = f;

  if ( pDefaultValue )
  {
    memcpy( m_pDataBlock + prevSize, pDefaultValue, fieldSize );
  }

  return true;
}
コード例 #2
0
ファイル: PEPacket.cpp プロジェクト: carribus/firecell
void PEPacket::SetFieldValue(const string& name, void* pValue)
{
  if ( !m_pDataBlock || !pValue )
    return;

  if ( !FieldExists(name) )
    return;

  Field f = m_fields[name];

  memcpy( m_pDataBlock + f.offset, pValue, f.elem_count * f.elem_width );
}
コード例 #3
0
ファイル: mainFrm.cpp プロジェクト: zjhupo/MIBEditor
void TfrmMain::init()
{
    ListView1->Clear();
    ListView2->Clear();
    ListView3->Clear();
    ListView4->Clear();
    ClearSet();
    Reload();
    if(FADO->Connected)
    {
        ADOQuery1->SQL->Text="select * from Devices order by DevID";
        ADOQuery1->Open();
        AnsiString szSwitchName="";
        int fldidx=-1;
        while(!ADOQuery1->Eof)
        {
            TListItem *Item=ListView1->Items->Add();
            szSwitchName = ADOQuery1->FieldByName("DevName")->AsString;
            fldidx = FieldExists(ADOQuery1,"switchname");
            if(fldidx>-1)
                szSwitchName = ADOQuery1->Fields->Fields[fldidx]->AsString;
            Item->Caption= ADOQuery1->FieldByName("DevName")->AsString;//厂商
            Item->SubItems->Add(szSwitchName);                         //型号
            Item->SubItems->Add(ADOQuery1->FieldByName("Name")->AsString);//原来的名称改为识别符号
            Item->SubItems->Add(ADOQuery1->FieldByName("supportSNMP")->AsInteger==1?"支持":"不支持");
            Item->SubItems->Add(ADOQuery1->FieldByName("typOID")->AsString);
            Item->SubItems->Add(ADOQuery1->FieldByName("saveOID")->AsString);
            Item->SubItems->Add(ADOQuery1->FieldByName("saveValue")->AsString);
            Item->SubItems->Add(ADOQuery1->FieldByName("Telnet")->AsString);
            Item->SubItems->Add(ADOQuery1->FieldByName("maxportnum")->AsString);


            Item->SubItems->Add(ADOQuery1->FieldByName("DevID")->AsString);//DevID
            ADOQuery1->Next();
        }
        //OperaMode
        ADOQuery1->SQL->Text="select * from OperaMode order by ModeID";
        ADOQuery1->Open();
        while(!ADOQuery1->Eof)
        {
            TListItem *Item=ListView2->Items->Add();
            Item->Caption=ADOQuery1->FieldByName("ModeID")->AsString;
            Item->SubItems->Add(ADOQuery1->FieldByName("remark")->AsString);
            ADOQuery1->Next();
        }
    }
}
コード例 #4
0
ファイル: ArcViewLayer.cpp プロジェクト: hkaiser/TRiAS
///////////////////////////////////////////////////////////////////////////////
// Export eines Objektes
HRESULT CArcViewLayer::ExportData (
	GSTRUCT *pGS, MFELD *pMF, LPCSTR pcUIdent, CArcViewLayerAttributes *pMap)
{
OBJECTTYPE rgType = GetType();
int iShapeId = -1;
int iObjTyp = pGS -> Typ;

	_ASSERTE(rgType == ObjType2OBJECTTYPE(pGS -> Typ, true));	// Objekttyp muß stimmen

// Geometrie erzeugen
	if (OBJECTTYPE_Area == rgType) {
	// Anzahl der Konturen feststellen und Konturfeld zusammenbauen
	int iKCnt = 1;
	vector<int> Cnts(1);
	int iCurr = 0;

		Cnts[0] = 0;
		for (int i = 0; 0 != pGS -> cnt[i]; ++i) {
			if (i > 0) 
				Cnts.push_back(iCurr);
			iCurr += pGS -> cnt[i];
		}
		iKCnt = i;

		_ASSERTE(iKCnt > 0 && iKCnt == Cnts.size());

	// Objekt erzeugen
	CArcViewObject Obj(SHPCreateObject(m_nShapeType, -1, iKCnt, Cnts.begin(), NULL,
						pGS -> GSize, pGS -> x, pGS -> y, NULL, NULL));

		iShapeId = SHPWriteObject(m_hSHP, -1, Obj);

	} else {
	// Objekt erzeugen
	CArcViewObject Obj(SHPCreateSimpleObject(m_nShapeType, pGS -> GSize, pGS -> x, pGS -> y, NULL));

		iShapeId = SHPWriteObject(m_hSHP, -1, Obj);
	}
	if (iShapeId == -1)
		return E_FAIL;

// Attribute sicherstellen (bei TRiAS-Datenquellen jedesmal)
	if (!HasFields() || DEX_GetTRiASDataSourceEx(DEX_GetObjectsProject(pGS -> Id))) {
	// sämtliche Attribute dieses Layers durchgehen und ggf. erzeugen
		for (CArcViewLayerAttributes::iterator it = pMap -> begin(); it != pMap -> end(); ++it) {
		// Feld in Datei erzeugen
		int iField = -1;
		CArcViewAttribute &rAttr = (*it).second;
		LPCSTR pcName = rAttr.GetName();

			if (OBJECTTYPE_Text != m_rgType && !strcmp (pcName, g_cbLabelText))
				continue;		// Labeltext nur für Textobjekte
				
			if (FAILED(FieldExists (pcName, rAttr.GetTyp(), &iField))) 
			{
				RETURN_FAILED_HRESULT(AddField(pcName, rAttr.GetTyp(), rAttr.GetLen(), rAttr.GetDecimals(), &iField));
			}
			_ASSERTE(-1 != iField);

		// mehrerer Objekttypen eines Idents haben identischen Satz von Attributen
			_ASSERTE(-1 == (*it).second.GetField(iObjTyp) || 
					 (*it).second.GetField(iObjTyp) == iField ||
					 DEX_GetTRiASDataSourceEx(DEX_GetObjectsProject(pGS -> Id)));

		// Feldnummer beim Attribut speichern
			(*it).second.SetField(iField, iObjTyp);
		}

	// Textlabel für Textobjekte
		if (OBJECTTYPE_Text == m_rgType) {
		pair<CArcViewLayerAttributes::iterator, bool> p = 
			pMap -> insert (CArcViewLayerAttributes::value_type (-1, CArcViewAttribute(g_cbLabelText, 'a', _MAX_PATH)));

			if (p.second) {
			int iField = -1;

				it = p.first;
				if (FAILED(FieldExists (g_cbLabelText, FTString, &iField))) 
				{
					RETURN_FAILED_HRESULT(AddField(g_cbLabelText, FTString, _MAX_PATH, 0, &iField));
				}
				
				_ASSERTE(-1 != iField);
				(*it).second.SetField(iField, iObjTyp);						
			}
		}
		SetHasFields();
	}
	
// Attributwerte schreiben
	if (NULL != pMF) {
	// nur, wenn mindestens ein Attribut ausgegeben werden soll
		for (MFELD *pMFT = pMF; 0 != pMFT -> MCode; ++pMFT) {
			if (NULL != pMap) {
			CArcViewLayerAttributes::iterator it = pMap -> find (pMFT -> MCode);

				_ASSERTE(it != pMap -> end());	// Attribut sollte (jetzt) existieren
				if (it != pMap -> end()) {
				// Feld muß bereits erzeugt worden sein und Typ muß mit DBF übereinstimmen
				int iField = (*it).second.GetField(iObjTyp);

					_ASSERTE(-1 != iField);
					_ASSERTE((*it).second.GetTyp() == DBFGetFieldInfo (m_hDBF, iField, NULL, NULL, NULL));

				// Wert je nach Typ in die Datenbank schreiben
					switch ((*it).second.GetTyp()) {
					case FTString:
						{
						char cbBuffer[_MAX_PATH] = { '\0' };

							if (NULL != pMFT -> MText)
								OemToCharBuff(pMFT -> MText, cbBuffer, min(MAX_DBASEFIELD_LEN, strlen(pMFT -> MText))+1);	// '\0' mit konvertieren
							DBFWriteStringAttribute(m_hDBF, iShapeId, iField, cbBuffer);
						}
						break;

					case FTInteger:
						DBFWriteIntegerAttribute(m_hDBF, iShapeId, iField, (NULL != pMFT -> MText) ? atol(pMFT -> MText) : 0);
						break;

					case FTDouble:
						DBFWriteDoubleAttribute(m_hDBF, iShapeId, iField, (NULL != pMFT -> MText) ? atof(pMFT -> MText) : 0.0);
						break;
					}
				}
			} else {
				_ASSERTE(NULL != pMap);		// eigentlich sollte eine Map da sein

			// keine Map, also erstmal leeren Datensatz schreiben
			int iCnt = DBFGetFieldCount(m_hDBF);

				for (int i = 0; i < iCnt; ++i) {
					switch (DBFGetFieldInfo(m_hDBF, i, NULL, NULL, NULL)) {
					case FTString:
						DBFWriteStringAttribute(m_hDBF, iShapeId, i, g_cbNil);
						break;

					case FTInteger:
						DBFWriteIntegerAttribute(m_hDBF, iShapeId, i, 0);
						break;

					case FTDouble:
						DBFWriteDoubleAttribute(m_hDBF, iShapeId, i, 0.0);
						break;
					}
				}
			}
		}
	}
	return S_OK;
}
コード例 #5
0
ファイル: fox.c プロジェクト: BlastTNG/flight
//*********************************************************
// Make the format file
//*********************************************************
void MakeFormatFile(char *filedirname) {
  char formatfilename[1024];
  FILE *formatfile;
  int i_field;
  int i_derived;
  char fieldU[1024];

  /*   Make format File   */
  sprintf(formatfilename, "%s/format", filedirname);

  formatfile = fopen(formatfilename, "w");
  if (formatfile == NULL) {
    fprintf(stderr,"Could not open format file %s", formatfilename);
    exit(0);
  }
  for (i_field = 0; i_field < n_framefields; i_field++) {
    // if the frame field already appears in the stream list
    // then we won't add it to the format file, and we will
    // set the file pointer to point to /dev/null in
    // OpenDirfilePointers.
    framefieldUnique[i_field] = FrameFieldIsUnique(frameList[i_field]);
    
    if (framefieldUnique[i_field]) {
      convertToUpper( framefields[i_field]->field, fieldU);
      fprintf(formatfile, "%-16s RAW    %c 1\n", framefields[i_field]->field, framefields[i_field]->type);
      fprintf(formatfile, "%-16s LINCOM 1 %16s %.12e %.12e 1\n", fieldU, framefields[i_field]->field,
              framefields[i_field]->m_c2e, framefields[i_field]->b_e2e);
      if (framefields[i_field]->quantity[0]!='\0') {
        fprintf(formatfile, "%s/quantity STRING %s\n",fieldU, framefields[i_field]->quantity);
      }
      if (framefields[i_field]->units[0]!='\0') {
        fprintf(formatfile, "%s/units STRING %s\n",fieldU, framefields[i_field]->units);
      }
    }
  }
#ifdef __SPIDER__
  for (i_field = 0; i_field < NUM_ARRAY_STAT; i_field++) {
    fprintf(formatfile, "%16s RAW c 1\n", GetArrayFieldName(i_field));
  }
#endif

  for (i_field = 0; i_field < n_streamfields; i_field++) {
    convertToUpper( streamfields[i_field]->field, fieldU);
    fprintf(formatfile, "%-16s RAW    %c %d\n", streamfields[i_field]->field, streamfields[i_field]->type,
            streamList[channelset_oth][i_field].samples_per_frame);
    fprintf(formatfile, "%-16s LINCOM 1 %16s %.12e %.12e 1\n", fieldU, streamfields[i_field]->field,
           streamfields[i_field]->m_c2e, streamfields[i_field]->b_e2e);
    if (streamfields[i_field]->quantity[0]!='\0') {
      fprintf(formatfile, "%s/quantity STRING %s\n",fieldU, streamfields[i_field]->quantity);
    }
    if (streamfields[i_field]->units[0]!='\0') {
      fprintf(formatfile, "%s/units STRING %s\n",fieldU, streamfields[i_field]->units);
    }
  }

  fprintf(formatfile, "/REFERENCE %s\n", streamfields[n_streamfields-1]->field);
  // the Time field
  //fprintf(formatfile, "Time RAW d 1\n/REFERENCE Time\n");

  // Derived channels
  for (i_derived = 0; DerivedChannels[i_derived].comment.type != DERIVED_EOC_MARKER; ++i_derived) {
      switch (DerivedChannels[i_derived].comment.type) {
      case 'b': /* bitfield */
        if (FieldSupported(DerivedChannels[i_derived].bitfield.source)) {
          int j;
          // write bitfield
          fprintf(formatfile, "\n# %s BITFIELD:\n", DerivedChannels[i_derived].bitfield.source);
          for (j = 0; j < 16; ++j) {
            if (DerivedChannels[i_derived].bitfield.field[j][0]!='\0') {
              fprintf(formatfile, "%-16s BIT %-16s %i\n", DerivedChannels[i_derived].bitfield.field[j],
                  DerivedChannels[i_derived].bitfield.source, j);
            }
          }
        }
        break;
      case '2': /* lincom2 */
        if (FieldExists(DerivedChannels[i_derived].lincom2.field)) {
          continue;
        }

        if (FieldSupported(DerivedChannels[i_derived].lincom2.source)) {
          if (FieldSupported(DerivedChannels[i_derived].lincom2.source2)) {
            // write lincom2
            fprintf(formatfile, 
                 "%-16s LINCOM 2 %-16s %.12e %.12e %-16s %.12e %.12e\n",
                 DerivedChannels[i_derived].lincom2.field, DerivedChannels[i_derived].lincom2.source,
                 DerivedChannels[i_derived].lincom2.m_c2e, DerivedChannels[i_derived].lincom2.b_e2e,
                 DerivedChannels[i_derived].lincom2.source2,
                 DerivedChannels[i_derived].lincom2.m2_c2e,
                 DerivedChannels[i_derived].lincom2.b2_e2e);
          }
        }
        break;
      case 'w': /* bitword  */
        if (FieldSupported(DerivedChannels[i_derived].bitword.source)) {
          // write bitword
          fprintf(formatfile, "%-16s BIT %-16s %i %i\n",
            DerivedChannels[i_derived].bitword.field, DerivedChannels[i_derived].bitword.source,
            DerivedChannels[i_derived].bitword.offset,
            DerivedChannels[i_derived].bitword.length);
        }
        break;
      case 't': /* linterp  */
        if (FieldSupported(DerivedChannels[i_derived].linterp.source)) {
          // write linterp
          fprintf(formatfile, "%-16s LINTERP %-16s %s\n",
            DerivedChannels[i_derived].linterp.field, DerivedChannels[i_derived].linterp.source,
            DerivedChannels[i_derived].linterp.lut);
        }
        break;
      case 'p': /* phase */
        if (FieldSupported(DerivedChannels[i_derived].phase.source)) {
          // write phase
          fprintf(formatfile, "%-16s PHASE %-16s %i\n",
            DerivedChannels[i_derived].phase.field, DerivedChannels[i_derived].phase.source,
            DerivedChannels[i_derived].phase.shift);
        }
        break;
      case 'c': /* lincom */
        if (FieldExists(DerivedChannels[i_derived].lincom.field)) {
          continue;
        }

        if (FieldSupported(DerivedChannels[i_derived].lincom.source)) {
          // write lincom
          fprintf(formatfile, "%-16s LINCOM 1 %-16s %.12e %.12e\n",
            DerivedChannels[i_derived].lincom.field, DerivedChannels[i_derived].lincom.source,
            DerivedChannels[i_derived].lincom.m_c2e, DerivedChannels[i_derived].lincom.b_e2e);
        }
        break;
      case '#': /* comment -- do nothing */
        break;
      case 'u': /* Units metadata */
        if (FieldSupported(DerivedChannels[i_derived].units.source)) {
          // write units
          fprintf(formatfile, "%s/units STRING %s\n%s/quantity STRING %s\n",
            DerivedChannels[i_derived].units.source, DerivedChannels[i_derived].units.units,
            DerivedChannels[i_derived].units.source, DerivedChannels[i_derived].units.quantity);
        }
        break;
      default:  // unrecognized -- do nothing
        break;
    }
  }

  /* Hack for a few important derived of derived fields: BLAST10 and probably BLAST12 */
/*
  fprintf(formatfile, "DR_INFO_IO_RW    LINCOM 2 DR_INFO_OPEN_RW  1.000000000000e+00 0.000000000000e+00 DR_INFO_INIT_1_RW 2.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "DR_INFO_IO_EL    LINCOM 2 DR_INFO_OPEN_EL  1.000000000000e+00 0.000000000000e+00 DR_INFO_INIT_1_EL 2.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "DR_INFO_IO_PIV   LINCOM 2 DR_INFO_OPEN_PIV 1.000000000000e+00 0.000000000000e+00 DR_INFO_INIT_1_PIV 2.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "DR_INFO_RIO_EL   LINCOM 2 DR_INFO_RESET_EL 4.000000000000e+00 0.000000000000e+00 DR_INFO_IO_EL    1.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "DR_INFO_RIO_PIV  LINCOM 2 DR_INFO_RESET_PIV 4.000000000000e+00 0.000000000000e+00 DR_INFO_IO_PIV   1.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "DR_INFO_RIO_RW   LINCOM 2 DR_INFO_RESET_RW 4.000000000000e+00 0.000000000000e+00 DR_INFO_IO_RW    1.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "POT_STATE        LINCOM 2 POT_IS_CLOSED    2.000000000000e+00 0.000000000000e+00 POT_IS_OPEN      1.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "LHE_STATE        LINCOM 2 LHE_IS_CLOSED    2.000000000000e+00 0.000000000000e+00 LHE_IS_OPEN      1.000000000000e+00 0.000000000000e+00\n");
  fprintf(formatfile, "LN_STATE         LINCOM 2 LN_IS_CLOSED     2.000000000000e+00 0.000000000000e+00 LN_IS_OPEN       1.000000000000e+00 0.000000000000e+00\n");
*/

  fclose(formatfile);

}