Skip to content

Commit

Permalink
cmd and tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Nov 19, 2024
1 parent 48e14ed commit e97fda7
Show file tree
Hide file tree
Showing 61 changed files with 676 additions and 674 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/tests-ubuntu-installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,24 @@ jobs:
run: |
ls -l test/uru2011mini/dic-to-csv
ls -l test/uru2011mini/dicx-to-csv
validate_csv() {
local file=$1
local expected_lines=$2
local expected_columns=$3
# Get the number of lines
actual_lines=$(wc -l < "$file")
# Get the number of columns (assuming the first line contains the headers)
actual_columns=$(head -n 1 "$file" | awk -F';' '{print NF}')
if [[ "$actual_lines" -eq "$expected_lines" && "$actual_columns" -eq "$expected_columns" ]]; then
echo "Validation passed for $file"
else
echo "Validation failed for $file: expected $expected_lines lines and $expected_columns columns, but got $actual_lines lines and $actual_columns columns"
exit 1
fi
}
validate_csv "test/uru2011mini/dic-to-csv/SEXO.csv" 38 4
validate_csv "test/uru2011mini/dicx-to-csv/SEXO.csv" 38 4
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,4 @@ $(OBJ_DIR)/moc_%.o: $(OBJ_DIR)/moc_%.cpp
clean:
rm -rf $(OBJ_DIR) $(LIB_DIR) $(TARGET_REDATAM) $(TARGET_GUI)

format: $(shell find . -name '*.h') $(shell find . -name '*.hpp') $(shell find . -name '*.cpp')
@${clang_format} -i $?

.PHONY: all clean nogui
.PHONY: all clean nogui
23 changes: 21 additions & 2 deletions dev/03-test-with-valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ make clean

make -f Makefile-debug

mkdir -p test/uru2011mini

valgrind --leak-check=full --track-origins=yes --log-file=test/uru2011mini/log-dic-to-csv.txt ./redatam test/uru2011mini/uru2011mini.dic test/uru2011mini/dic-to-csv

valgrind --leak-check=full --track-origins=yes --log-file=test/uru2011mini/log-dicx-to-csv.txt ./redatam test/uru2011mini/uru2011mini.dicx test/uru2011mini/dicx-to-csv

validate_csv() {
local file=$1
local expected_lines=$2
local expected_columns=$3

# Get the number of lines
actual_lines=$(wc -l < "$file")
# Get the number of columns (assuming the first line contains the headers)
actual_columns=$(head -n 1 "$file" | awk -F';' '{print NF}')

if [[ "$actual_lines" -eq "$expected_lines" && "$actual_columns" -eq "$expected_columns" ]]; then
echo "Validation passed for $file"
else
echo "Validation failed for $file: expected $expected_lines lines and $expected_columns columns, but got $actual_lines lines and $actual_columns columns"
exit 1
fi
}

validate_csv "test/uru2011mini/dic-to-csv/SEXO.csv" 38 4
validate_csv "test/uru2011mini/dicx-to-csv/SEXO.csv" 38 4
21 changes: 21 additions & 0 deletions dev/format-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Find clang-format
clang_format=$(which clang-format-19)

# Check if clang-format is installed
if [ -z "$clang_format" ]; then
echo "clang-format-19 is not installed. Please install it first."
exit 1
fi

# Find all .h, .hpp, and .cpp files, excluding those in the vendor/ directory
files=$(find . -path ./vendor -path ./rpkg/src/vendor -path ./pypkg/redatam/vendor -prune -o -name '*.h' -o -name '*.hpp' -o -name '*.cpp' -print)

# Format each file
for file in $files; do
echo "Formatting $file"
$clang_format -i "$file"
done

echo "Formatting complete."
21 changes: 0 additions & 21 deletions format-code.sh

This file was deleted.

10 changes: 5 additions & 5 deletions include/database/RedatamDatabase.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef REDATAMLIB_REDATAMDATABASE_HPP
#define REDATAMLIB_REDATAMDATABASE_HPP

#include <stdexcept> // invalid_argument
#include <stdexcept> // invalid_argument
#include <string>
#include <vector>

Expand All @@ -12,7 +12,7 @@ using std::string;
using std::vector;

class RedatamDatabase {
public:
public:
// Throws invalid_argument
explicit RedatamDatabase(const string &fileName);
~RedatamDatabase() = default;
Expand All @@ -23,12 +23,12 @@ class RedatamDatabase {
void ExportCSVFiles(const string &outputDir);
void ExportSummary(const string &outputDir);

private:
private:
vector<Entity> m_entities;

void OpenDictionary(const string &fileName);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_REDATAMDATABASE_HPP
#endif // REDATAMLIB_REDATAMDATABASE_HPP
10 changes: 5 additions & 5 deletions include/entities/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <memory>
#include <string>
#include <utility> // pair
#include <utility> // pair
#include <vector>

#include "ByteArrayReader.hpp"
Expand All @@ -16,7 +16,7 @@ using std::string;
using std::vector;

class Entity {
public:
public:
Entity();
Entity(const string &name, const string &parentName,
const string &description, const string &idxFileName,
Expand All @@ -39,7 +39,7 @@ class Entity {
void AttachChild(Entity *child);
void AttachVariables(shared_ptr<vector<Variable>> variables);

private:
private:
string m_name;
string m_parentName;
string m_description;
Expand All @@ -50,6 +50,6 @@ class Entity {
ByteArrayReader m_reader;
size_t m_rowsCount;
};
} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_ENTITY_HPP
#endif // REDATAMLIB_ENTITY_HPP
16 changes: 8 additions & 8 deletions include/entities/Variable.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef REDATAMLIB_VARIABLE_HPP
#define REDATAMLIB_VARIABLE_HPP

#include <memory> // shared_ptr
#include <memory> // shared_ptr
#include <string>
#include <utility> // pair
#include <utility> // pair
#include <vector>

namespace RedatamLib {
Expand All @@ -13,12 +13,12 @@ using std::string;
using std::vector;

enum VarType { BIN, CHR, DBL, INT, LNG, PCK, NA };
using Tag = pair<string, string>; // Tag = <Key, Value>
using Tag = pair<string, string>; // Tag = <Key, Value>

class ByteArrayReader; // Forward declaration
class ByteArrayReader; // Forward declaration

class Variable {
public:
public:
Variable();
Variable(const string &name, VarType type, const string &idxFileName,
size_t dataSize, const string &filter, const string &range,
Expand All @@ -36,7 +36,7 @@ class Variable {
size_t GetDecimals() const;
shared_ptr<void> GetValues() const;

private:
private:
string m_name;
VarType m_type;
string m_idxFileName;
Expand All @@ -57,6 +57,6 @@ class Variable {
void ParseFloats(ByteArrayReader &reader);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_VARIABLE_HPP
#endif // REDATAMLIB_VARIABLE_HPP
10 changes: 5 additions & 5 deletions include/exporters/CSVExporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "Variable.hpp"

namespace RedatamLib {
using std::mutex;
using std::string;
using std::vector;
using std::mutex;

class CSVExporter {
public:
public:
explicit CSVExporter(const string &outputDirectory);
~CSVExporter() = default;

Expand All @@ -23,7 +23,7 @@ class CSVExporter {

void ExportAll(vector<Entity> &entities);

private:
private:
string m_path;
mutable mutex m_mtx;

Expand All @@ -32,6 +32,6 @@ class CSVExporter {
void CreateVariablesData(Entity &e) const;
void ThreadExport(size_t start, size_t end, vector<Entity> &entities) const;
};
} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_CSVEXPORTER_HPP
#endif // REDATAMLIB_CSVEXPORTER_HPP
8 changes: 4 additions & 4 deletions include/exporters/ParentIDCalculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace RedatamLib {
class ParentIDCalculator {
public:
public:
explicit ParentIDCalculator(Entity *child);
~ParentIDCalculator() = default;

Expand All @@ -14,11 +14,11 @@ class ParentIDCalculator {

size_t GetParentID(size_t currRow);

private:
private:
Entity *m_child;
size_t m_currID;
size_t m_currLimit;
};
} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_PARENTIDCALCULATOR_HPP
#endif // REDATAMLIB_PARENTIDCALCULATOR_HPP
8 changes: 4 additions & 4 deletions include/exporters/XMLExporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ using std::string;
using std::vector;

class XMLExporter {
public:
public:
explicit XMLExporter(const string &outputDirectory);
~XMLExporter() = default;
void ExportSummary(vector<Entity> &entities);

private:
private:
string m_path;
pugi::xml_document m_doc;

Expand All @@ -30,6 +30,6 @@ class XMLExporter {
static string GetVarType(VarType type);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_XMLEXPORTER_HPP
#endif // REDATAMLIB_XMLEXPORTER_HPP
10 changes: 5 additions & 5 deletions include/readers/BitArrayReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define REDATAMLIB_BITARRREADER_HPP

#include <bitset>
#include <cstdint> // uint16_t, uint32_t
#include <cstdint> // uint16_t, uint32_t
#include <vector>

namespace RedatamLib {
using std::bitset;
using std::vector;

class BitArrayReader {
public:
public:
explicit BitArrayReader(size_t dataSize);
~BitArrayReader() = default;

Expand All @@ -19,7 +19,7 @@ class BitArrayReader {

void ParseBits(vector<uint32_t> *results, uint32_t data);

private:
private:
size_t m_varSize;
size_t m_remainderSize;
bitset<32> m_mask;
Expand All @@ -29,6 +29,6 @@ class BitArrayReader {
bitset<32> CreateMask(size_t size);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_BITARRREADER_HPP
#endif // REDATAMLIB_BITARRREADER_HPP
14 changes: 7 additions & 7 deletions include/readers/ByteArrayReader.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef REDATAMLIB_BYTEARRREADER_HPP
#define REDATAMLIB_BYTEARRREADER_HPP

#include <cstddef> // size_t
#include <cstdint> // uint16_t, uint32_t
#include <stdexcept> // out_of_range, length_error
#include <cstddef> // size_t
#include <cstdint> // uint16_t, uint32_t
#include <stdexcept> // out_of_range, length_error
#include <string>
#include <vector>

Expand All @@ -14,7 +14,7 @@ using std::string;
using std::vector;

class ByteArrayReader {
public:
public:
ByteArrayReader();
// throws ios_base::failure if fails to open file
ByteArrayReader(const string &filePath);
Expand Down Expand Up @@ -48,7 +48,7 @@ class ByteArrayReader {
uint16_t ReadInt16BE();
uint32_t ReadInt32BE();

private:
private:
vector<unsigned char> m_data;
size_t m_currPos;
size_t m_endPos;
Expand All @@ -58,6 +58,6 @@ class ByteArrayReader {
bool IsValidStr(const string &str);
};

} // namespace RedatamLib
} // namespace RedatamLib

#endif // REDATAMLIB_BYTEARRREADER_HPP
#endif // REDATAMLIB_BYTEARRREADER_HPP
Loading

0 comments on commit e97fda7

Please sign in to comment.