Skip to content

Commit

Permalink
refactoring cfapi
Browse files Browse the repository at this point in the history
  • Loading branch information
ava57r committed Mar 29, 2018
1 parent a7606e1 commit f8a58f9
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 228 deletions.
4 changes: 2 additions & 2 deletions src/gtool1cd/models/table_data_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ QVariant TableDataModel::data(const QModelIndex &index, int role) const
}

V8Catalog cat(data_stream, true, false);
if (cat.isOpen() && cat.IsCatalog()) {
if (cat.isOpen() && cat.is_catalog()) {
QString result("{catalog}");
}
TMemoryStream *mem = new TMemoryStream;
Expand Down Expand Up @@ -158,7 +158,7 @@ V8Catalog *TableDataModel::getCatalog(const QModelIndex &index) const

{
auto *cat = new V8Catalog(data_stream, false, false);
if (cat->isOpen() && cat->IsCatalog()) {
if (cat->isOpen() && cat->is_catalog()) {
return cat;
}
delete cat;
Expand Down
22 changes: 11 additions & 11 deletions src/gtool1cd/models/v8catalog_tree_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int V8CatalogTreeModel::rowCount(const QModelIndex &parent) const
if (parentItem == nullptr) {
return catalog->v8files().size();
}
if (parentItem->IsCatalog()) {
return parentItem->GetCatalog()->v8files().size();
if (parentItem->is_catalog()) {
return parentItem->get_catalog()->v8files().size();
}
return 0;
}
Expand All @@ -33,12 +33,12 @@ int V8CatalogTreeModel::columnCount(const QModelIndex &parent) const

static V8File *get_file(V8Catalog *cat, int file_index)
{
auto f = cat->GetFirst();
auto f = cat->get_first();
while (file_index--) {
if (f == nullptr) {
return nullptr;
}
f = f->GetNext();
f = f->get_next();
}
return f;
}
Expand All @@ -55,7 +55,7 @@ QModelIndex V8CatalogTreeModel::index(int row, int column, const QModelIndex &pa

V8Catalog *parentItem = parent.internalPointer() == nullptr
? catalog
: static_cast<V8File*>(parent.internalPointer())->GetCatalog();
: static_cast<V8File*>(parent.internalPointer())->get_catalog();
V8File *childItem = get_file(parentItem, row);
if (childItem == nullptr) {
return QModelIndex();
Expand All @@ -69,8 +69,8 @@ static int index_of(V8Catalog *parent, V8File *child)
if (parent == nullptr) {
return -1;
}
auto f = parent->GetFirst();
for (int i = 0; f != nullptr; i++, f = f->GetNext()) {
auto f = parent->get_first();
for (int i = 0; f != nullptr; i++, f = f->get_next()) {
if (f == child) {
return i;
}
Expand All @@ -90,12 +90,12 @@ QModelIndex V8CatalogTreeModel::parent(const QModelIndex &child) const
return QModelIndex();
}

V8Catalog *parentItem = childItem->GetParentCatalog();
V8Catalog *parentItem = childItem->get_parent_catalog();
if (parentItem == catalog) {
return createIndex(0, 0, nullptr);
}
int parent_index = index_of(parentItem->GetParentCatalog(), parentItem->GetSelfFile());
return createIndex(parent_index, 0, parentItem->GetSelfFile());
int parent_index = index_of(parentItem->get_parent_catalog(), parentItem->get_self_file());
return createIndex(parent_index, 0, parentItem->get_self_file());
}

QVariant V8CatalogTreeModel::data(const QModelIndex &index, int role) const
Expand All @@ -110,7 +110,7 @@ QVariant V8CatalogTreeModel::data(const QModelIndex &index, int role) const
if (item == nullptr) {
return QString(catalogName);
}
return QString::fromStdString(item->GetFileName());
return QString::fromStdString(item->get_file_name());
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/tool1cd/Class_1CD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ bool T_1CD::recursive_test_stream_format(TStream *str, const string &path, bool
.add_detail("Путь", path);
}

if(!cat || !cat->GetFirst())
if(!cat || !cat->get_first())
{

if(_s->GetSize() >= 16)
Expand Down Expand Up @@ -1145,31 +1145,31 @@ bool T_1CD::recursive_test_stream_format(V8Catalog *cat, const string &path)
V8File* v8fp;

result = true;
v8f = cat->GetFirst();
v8f = cat->get_first();
while(v8f)
{
try
{
c = v8f->GetCatalog();
c = v8f->get_catalog();
}
catch(...)
{
throw DetailedException("Ошибка тестирования. Ошибка чтения формата.")
.add_detail("Путь", path);
}
if (c) {
result = recursive_test_stream_format(c, path + "/" + v8f->GetFileName());
result = recursive_test_stream_format(c, path + "/" + v8f->get_file_name());
} else
{
string fname = v8f->GetFileName();
string fname = v8f->get_file_name();
if(fname != "module" && fname != "text")
{
result = recursive_test_stream_format(v8f->get_stream(), path + "/" + v8f->GetFileName());
result = recursive_test_stream_format(v8f->get_stream(), path + "/" + v8f->get_file_name());
}
}
v8fp = v8f;
v8f = v8f->GetNext();
v8fp->Close();
v8f = v8f->get_next();
v8fp->close();
}
return result;
}
Expand Down
30 changes: 15 additions & 15 deletions src/tool1cd/ConfigStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ ConfigFile* ConfigStorageCFFile::readfile(const std::string &path)
V8Catalog* c = cat;
for (auto i = fname.find("\\"); i != string::npos; i = fname.find("\\"))
{
V8File *f = c->GetFile(fname.substr(0, i - 1));
V8File *f = c->get_file(fname.substr(0, i - 1));
if(!f) {
return nullptr;
}
c = f->GetCatalog();
c = f->get_catalog();
if(!c) {
return nullptr;
}
fname = fname.substr(i + 1, fname.size() - i - 1);
}
V8File *f = c->GetFile(fname);
V8File *f = c->get_file(fname);
if (!f) {
return nullptr;
}
if (!f->Open()) {
if (!f->open()) {
return nullptr;
}
cf = new ConfigFile;
Expand Down Expand Up @@ -147,7 +147,7 @@ bool ConfigStorageCFFile::writefile(const std::string &path, TStream *str)
fname = fname.substr(i + 1, fname.size() - i - 1);
}
f = c->createFile(fname);
f->Write(str);
f->write(str);
return true;
}

Expand All @@ -163,7 +163,7 @@ void ConfigStorageCFFile::close(ConfigFile* cf)
V8File* f;

f = (V8File*)cf->addin;
f->Close();
f->close();
delete cf;
}

Expand All @@ -183,7 +183,7 @@ bool ConfigStorageCFFile::fileexists(const std::string &path) const
if (i != string::npos) {
fname = fname.substr(0, i - 1);
}
V8File *f = cat->GetFile(fname);
V8File *f = cat->get_file(fname);
return f != nullptr;
}

Expand Down Expand Up @@ -422,24 +422,24 @@ ConfigFile* ConfigStorageTable::readfile(const std::string &path)
}
V8Catalog *parent_cat = top_file->cat;
for (auto i = fname.find("\\"); i != string::npos; i = fname.find("\\")) {
V8File *f = parent_cat->GetFile(fname.substr(0, i - 1));
V8File *f = parent_cat->get_file(fname.substr(0, i - 1));
if (!f) {
// TODO: бросить исключение???
return nullptr;
}
parent_cat = f->GetCatalog();
parent_cat = f->get_catalog();
if (!parent_cat) {
// TODO: бросить исключение???
return nullptr;
}
fname = fname.substr(i + 1, fname.size() - i - 1);
}
V8File *f = parent_cat->GetFile(fname);
V8File *f = parent_cat->get_file(fname);
if (!f) {
// TODO: бросить исключение???
return nullptr;
}
if (!f->Open()) {
if (!f->open()) {
// TODO: бросить исключение???
return nullptr;
}
Expand Down Expand Up @@ -485,7 +485,7 @@ void ConfigStorageTable::close(ConfigFile* cf)
}
else if(cfa->variant == ConfigStorageTableAddinVariant::V8File)
{
cfa->f->Close();
cfa->f->close();
}
delete cfa;
delete cf;
Expand Down Expand Up @@ -520,9 +520,9 @@ bool ConfigStorageTable::save_config(const boost::filesystem::path &file_name)
if(top_file->ropen())
{
V8File* file = catalog->createFile(top_file->name);
file->time_create(top_file->file->ft_create);
file->time_modify(top_file->file->ft_modify);
file->WriteAndClose(top_file->rstream);
file->set_time_create(top_file->file->ft_create);
file->set_time_modify(top_file->file->ft_modify);
file->write_and_close(top_file->rstream);

top_file->close();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tool1cd/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool Field::save_blob_to_file(const TableRecord *rec, const std::string &_filena
}

V8Catalog *cat = new V8Catalog(_sx2, zippedContainer, true);
if(!cat->GetFirst())
if(!cat->get_first())
{
TFileStream temp_stream(boost::filesystem::path(_filename), fmCreate);
temp_stream.CopyFrom(_sx2, 0);
Expand Down
10 changes: 5 additions & 5 deletions src/tool1cd/SupplierConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::shared_ptr<SupplierConfig> SupplierConfigBuilder::build() {
}

int32_t SupplierConfigBuilder::get_version() const {
V8File* version_file = main_catalog->GetFile("version");
V8File* version_file = main_catalog->get_file("version");
if(!version_file) {
throw SupplierConfigReadException("Не найден файл version в конфигурации поставщика")
.add_detail("Таблица", _table_file->t->get_name())
Expand All @@ -162,23 +162,23 @@ V8File* SupplierConfigBuilder::get_file(const string &file_name) const {
V8File* result = nullptr;

if(get_version() < 100) { // 8.0
V8File* metadata_file = main_catalog->GetFile("metadata");
V8File* metadata_file = main_catalog->get_file("metadata");
if(metadata_file == nullptr) {
throw SupplierConfigReadException("Не найден каталог metadata в конфигурации поставщика")
.add_detail("Таблица", _table_file->t->get_name())
.add_detail("Имя файла", _table_file->name);
}

V8Catalog* cat2 = metadata_file->GetCatalog();
V8Catalog* cat2 = metadata_file->get_catalog();
if(cat2 == nullptr) {
throw SupplierConfigReadException("Файл metadata не является каталогом в конфигурации поставщика")
.add_detail("Таблица", _table_file->t->get_name())
.add_detail("Имя файла", _table_file->name);
}

result = cat2->GetFile(file_name);
result = cat2->get_file(file_name);
} else {
result = main_catalog->GetFile(file_name); // else 8.1 или 8.2
result = main_catalog->get_file(file_name); // else 8.1 или 8.2
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/tool1cd/cfapi/APIcfBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ unsigned WindowsTickToUnixSeconds(long long windowsTicks)
return (unsigned)(windowsTicks / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
}

int32_t stBlockHeader::data_size() const {
int32_t stBlockHeader::get_data_size() const {
string hex("0x");
hex.append(data_size_hex);

Expand All @@ -27,7 +27,7 @@ void stBlockHeader::set_data_size(int32_t value) {
std::begin(data_size_hex));
}

int32_t stBlockHeader::page_size() const {
int32_t stBlockHeader::get_page_size() const {
string hex("0x");
hex.append(page_size_hex);

Expand All @@ -43,7 +43,7 @@ void stBlockHeader::set_page_size(int32_t value) {
std::begin(page_size_hex));
}

int32_t stBlockHeader::next_page_addr() const {
int32_t stBlockHeader::get_next_page_addr() const {
string hex("0x");
hex.append(next_page_addr_hex);

Expand Down
21 changes: 11 additions & 10 deletions src/tool1cd/cfapi/APIcfBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const char _EMPTY_CATALOG_TEMPLATE[16] = {'\xff','\xff','\xff','\x7f',0,2,0,0,0,
const int32_t LAST_BLOCK = std::numeric_limits<int>::max();

//---------------------------------------------------------------------------
struct v8header_struct{
struct v8header_struct
{
int64_t time_create;
int64_t time_modify;
int32_t zero;
Expand All @@ -33,7 +34,7 @@ struct stElemAddr
int32_t data_addr;
int32_t fffffff; //всегда 0x7fffffff ?

constexpr static const uint32_t Size()
constexpr static const uint32_t size()
{
return 4 + 4 + 4;
}
Expand All @@ -47,7 +48,7 @@ struct stFileHeader
int32_t storage_ver {0}; // версия
int32_t reserved {0}; // всегда 0x00000000 ?

constexpr static const uint32_t Size()
constexpr static const uint32_t size()
{
return 4 + 4 + 4 + 4;
}
Expand All @@ -63,14 +64,14 @@ class stBlockHeader
EOL2_0D(0xd), EOL2_0A(0xa)
{}

static stBlockHeader create(int32_t block_data_size, int32_t page_size, int32_t next_page_addr);
static stBlockHeader create(int32_t block_data_size, int32_t get_page_size, int32_t get_next_page_addr);

constexpr static const uint32_t Size()
constexpr static const uint32_t size()
{
return 1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 1;
}

bool IsCorrect() const
bool is_correct() const
{
return EOL_0D == 0x0d
&& EOL_0A == 0x0a
Expand All @@ -81,19 +82,19 @@ class stBlockHeader
&& EOL2_0A == 0x0a;
}

int32_t data_size() const;
int32_t get_data_size() const;
void set_data_size(int32_t value);

int32_t page_size() const;
int32_t get_page_size() const;
void set_page_size(int32_t value);

int32_t next_page_addr() const;
int32_t get_next_page_addr() const;
void set_next_page_addr(int32_t value);

const std::string toString() const
{
auto _begin = reinterpret_cast<const char *>(this);
auto _end = _begin + Size();
auto _end = _begin + size();
std::string result(_begin, _end);
return result;
}
Expand Down
Loading

0 comments on commit f8a58f9

Please sign in to comment.