Skip to content

Commit

Permalink
Arreglando problemas de git por segunda vez
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark1024 committed Sep 17, 2013
0 parents commit 47ff860
Show file tree
Hide file tree
Showing 26 changed files with 1,821 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Proyecto_OA.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-14T16:55:40
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Proyecto_OA
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
adtfile.cpp \
adtfilerecord.cpp \
field.cpp \
fileheader.cpp \
newfieldwindow.cpp \
modifyfieldwindow.cpp \
record.cpp \
object.cpp \
primaryindex.cpp

HEADERS += mainwindow.h \
adtfile.h \
adtfilerecord.h \
field.h \
fileheader.h \
newfieldwindow.h \
modifyfieldwindow.h \
record.h \
object.h \
primaryindex.h

FORMS += mainwindow.ui \
newfieldwindow.ui \
modifyfieldwindow.ui
256 changes: 256 additions & 0 deletions Proyecto_OA.pro.user

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions adtfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "adtfile.h"

ADTFile::ADTFile()
{
}

ADTFile::~ADTFile()
{
this->FS.close();
}

bool ADTFile::open(string Path, ios_base::openmode flags)
{
this->Nombre = Path;
this->flags = flags;
this->FS.open(this->Nombre.c_str(), this->flags);
return this->isOpen();
}

bool ADTFile::close()
{
this->FS.close();
return !this->isOpen();
}

bool ADTFile::seekg(streamoff n, ios_base::seekdir flags)
{
this->FS.seekg(n,flags);
return this->FS.good();
}

bool ADTFile::seekp(streamoff n, ios_base::seekdir flags)
{
this->FS.seekp(n,flags);
return this->FS.good();
}

streamoff ADTFile::tellg()
{
return this->FS.tellg();
}

streamoff ADTFile::tellp(){
return this->FS.tellp();
}

int ADTFile::read(char* str, streamoff n)
{
if(this->isOpen()){
this->FS.read(str,n);
str[n+1] = '\0';
return FS.gcount();
}else{
return -1;
}
}

int ADTFile::write(const char* str, streamoff n){
if(this->isOpen()){
this->FS.write(str,n);
return this->FS.gcount();
}else{
return -1;
}
}

bool ADTFile::isOpen() const
{
return this->FS.is_open();
}

bool ADTFile::isEOF() const
{
if(this->isOpen()){
return this->FS.eof();
}else{
return false;
}
}

bool ADTFile::isBOF() const
{
bool retval = false;
if(this->isOpen()){

}
return retval;
}

bool ADTFile::flush()
{
if(!this->isOpen()){
return false;
}
return !this->FS.flush().fail();
}

bool ADTFile::isOk()
{
return this->FS.good();
}
35 changes: 35 additions & 0 deletions adtfile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef ADTFILE_H
#define ADTFILE_H

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

class ADTFile
{
public:
ADTFile();
virtual ~ADTFile();
virtual bool open(string = "", ios_base::openmode = ios_base::in | ios_base::out);
virtual bool close();
virtual bool seekg(streamoff, ios_base::seekdir);
virtual bool seekp(streamoff, ios_base::seekdir);
virtual streamoff tellg();
virtual streamoff tellp();
virtual int read(char*, streamoff);
virtual int write(const char*, streamoff);
virtual bool isOpen() const;
virtual bool isEOF() const;
virtual bool isBOF() const;
virtual bool flush();
virtual bool isOk();

protected:
string Nombre;
fstream FS;
ios_base::openmode flags;
};

#endif // ADTFILE_H
127 changes: 127 additions & 0 deletions adtfilerecord.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "adtfilerecord.h"

ADTFileRecord::ADTFileRecord():ADTFile()
{
this->header = new FileHeader();
}

ADTFileRecord::ADTFileRecord(string Name,int recordLength):ADTFile()
{
this->fileName = Name;
this->recordLength = recordLength;

this->header = new FileHeader();
}

ADTFileRecord::~ADTFileRecord()
{
this->FS.flush();
this->FS.close();

delete header;
}

void ADTFileRecord::seekgRecord(int recordNumber)
{
this->FS.seekg(this->dataStart + ((recordNumber-1) * this->recordLength));
}

void ADTFileRecord::seekpRecord(int recordNumber)
{
this->FS.seekp(this->dataStart + ((recordNumber-1) * this->recordLength));
}

string ADTFileRecord::readRecord(int recordNumber)
{
char* tmp = new char[this->recordLength];
this->seekgRecord(recordNumber);
this->FS.read(tmp,this->recordLength);
string str(tmp);
return str;
}

bool ADTFileRecord::writeRecord(string record)
{
if(record.length() != this->recordLength){
return false;
}

if(this->AvailList.isEmpty()){
FS.seekp(0,ios_base::end);
FS.write(record.c_str(),this->recordLength);
return !FS.fail();
}else{
this->seekpRecord(this->AvailList.pop());
this->FS.write(record.c_str(),this->recordLength);
}
return !FS.fail();
}

bool ADTFileRecord::updateRecord(int recordNumber, string record)
{
if(record.length() != this->recordLength){
return false;
}

this->seekpRecord(recordNumber);
FS.write(record.c_str(),this->recordLength);
return !FS.fail();
}

bool ADTFileRecord::deleteRecord(int recordNumber)
{
this->seekpRecord(recordNumber);
string mark = "*";

FS.write(mark.c_str(),mark.length());

if(FS.fail())
return false;
this->AvailList.push(recordNumber);
return true;
}

void ADTFileRecord::setDataStart(int dataStart)
{
this->dataStart = dataStart;
}

void ADTFileRecord::setRecordLength(int recordLength)
{
this->recordLength = recordLength;
}

void ADTFileRecord::readHeader(char* header)
{
char* c;
vector<char*> tmpFields;

c = strtok(header,"/");
tmpFields.push_back(c);
while(c != NULL){
c = strtok(NULL,"/");
tmpFields.push_back(c);
}

for(int i = 0; i < tmpFields.size()-1; i++){
string name = strtok(tmpFields[i],",");
char Type = strtok(NULL,",")[0];
int key = atoi(strtok(NULL,","));
int length = atoi(strtok(NULL,","));
int decimal = atoi(strtok(NULL,","));

Field* newField = new Field(name, Type, key, length, decimal);

this->header->addField(newField);
}
}

FileHeader* ADTFileRecord::getFileHeader()
{
return this->header;
}

int ADTFileRecord::getDataStart()
{
return this->dataStart;
}
46 changes: 46 additions & 0 deletions adtfilerecord.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef ADTFILERECORD_H
#define ADTFILERECORD_H

#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <QStack>
#include <iostream>

#include "adtfile.h"
#include "fileheader.h"

using namespace std;

class ADTFileRecord:public ADTFile
{
public:
ADTFileRecord();
ADTFileRecord(string, int);
virtual ~ADTFileRecord();
virtual void seekgRecord(int);
virtual void seekpRecord(int);
virtual string readRecord(int);
virtual bool writeRecord(string);
virtual bool updateRecord(int, string);
virtual bool deleteRecord(int);
//virtual void compact();
void setDataStart(int);
void setRecordLength(int);
void readHeader(char*);
FileHeader* getFileHeader();
virtual int getDataStart();

private:
int recordLength;
int dataStart;

FileHeader* header;
string fileName;
fstream FS;
QStack<int> AvailList;
};

#endif // ADTFILERECORD_H
Loading

0 comments on commit 47ff860

Please sign in to comment.