Methode zum einlesen und trennen von dateiinhalten gut?
-
hallo,
problemstellung:
ich muss eine datei einlesen welche mehrere "info" blöcke enthält...
im programm kann man dann zwischen den infoblöcken umschalten...
meine idee daher:
für jeden infoblock eine Stringlist, damit beim umschalten nur in eine andere list geswitched wird, und nicht andauernd neu gesucht usw werden muss...
vorgehensweise (gedacht)
1 file in List einlesen
2 Blöcke (beginnen immer mit 512) suchen
3 Anfans und Endzeile zwischenspeichern
4 Blöcke aus List in seperate lists kopierendazeiinhalt:
512 33 51332423480932840923483204 51423424234324234565565466 512 43443 51323423432423423432 512543242 513234234324 5145435345345435543543534543543 512 34 51332423480932840923483204 51423424234324234565565466 512 43443 51323423432423423432 512543242 513234234324 5145435345345435543543534543500000.h
//--------------------------------------------------------------------------- #ifndef offnen_splittemH #define offnen_splittemH //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Dialogs.hpp> #include <Menus.hpp> #include <utility> #include <vector> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // Von der IDE verwaltete Komponenten TOpenDialog *OpenDialog1; TMainMenu *MainMenu1; TMenuItem *Datei1; TMenuItem *ffnen1; TMemo *Memo1; void __fastcall ffnen1Click(TObject *Sender); private: // Anwender-Deklarationen public: // Anwender-Deklarationen TStringList* VDAList; //std::pair<int,int>* startStopArea; std::vector<std::pair<int,int> > startStopVector; int areaCounter; __fastcall TForm1(TComponent* Owner); std::vector<int> startStopPositions; void __fastcall FindAreas(); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif.cpp
#include <vcl.h> #pragma hdrstop #include "offnen_splittem.h" #include <vector> using namespace std; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::ffnen1Click(TObject *Sender) { if(OpenDialog1->Execute()) { //free memory not to seg_fault exception delete VDAList; VDAList = 0; //allocate new memory for list VDAList = new TStringList(); VDAList->LoadFromFile(OpenDialog1->FileName); //set all new startStopPositions.clear(); areaCounter = 0; //delete[] startStopArea; //Now get the area koords FindAreas(); //Debugoutput Memo1->Lines->Add("Anzahl Zeilen in Datei: " + String(VDAList->Count)); Memo1->Lines->Add("Bereiche: " + String(areaCounter)); } } //--------------------------------------------------------------------------- //fills startStopArea and areaCounter //that you are able to seperate it later void __fastcall TForm1::FindAreas() { int start, stop; //start und stop dea areals //search for areas (512 starts a area) int searchLen = VDAList->Count; for(int i = 0;i < searchLen;++i) { if(VDAList->Strings[i].SubString(0,3)=="512") { areaCounter++; startStopPositions.push_back(i); } } //alloc memory for pairs which includes the start and stop positions of an area //startStopArea = new pair<int,int>[areaCounter]; Memo1->Lines->Add("Positionen im Vector: " + String(startStopPositions.size())); //------------------------------------------------------ for(unsigned int i=0;i<startStopPositions.size();++i) Memo1->Lines->Add(String(startStopPositions.at(i))); //------------------------------------------------------ //Check if all vector-positions the same as the count of areas if(areaCounter!=startStopPositions.size()) ShowMessage("Fehler bei Synchronisation"); //fill the pairs with koords for(int i = 0;i < areaCounter; ++i) { //-----------manual methode-------------------- /*startStopArea[i].first = startStopPositions.at(i); //if if(i + 1 >= areaCounter) startStopArea[i].second = searchLen; else startStopArea[i].second = startStopPositions.at(i+1); if(i!=areaCounter-1) startStopArea[i].second = startStopArea[i].second -1 ; */ //---------------------------------------------------- //automatic vector works better start = startStopPositions.at(i); //end reached?? if(i+1 >= areaCounter) stop = searchLen; else stop = startStopPositions.at(i+1); //end of one area is not the same like the beginning of the next if(i!=areaCounter-1) --stop; / /fill up vector startStopVector.push_back(make_pair(start,stop)); //debugoutput Memo1->Lines->Add("Pair #" + String(i) + ": Start: " + String(startStopVector[i].first)+ " Stop: " + String(startStopVector[i].second)); } }ist die idee und das vorgehen so gut?
oder gibt es bedeutend bessere möglichkeiten?
und wie sieht meine umsetzung bis jetzt aus?
-
hm....ist das also eher nicht so gut?
wäre toll wenn jemand etwas dazu sagen könnte!
-
hm...sorry wenn ich nochmal störe, aber wenn einer mal eine meinung dazu abgeben könnte wäre echt super!
will ja keinen mist verzapfen!
-
Ja, di Funktion ist super...
-
hm....hört sich bisschen ironisch an
