Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ target_include_directories(mlcpppy PUBLIC ${PROJECT_SOURCE_DIR}/include)
# Executável de exemplo
# -------------------------------
add_executable(example_main examples/main.cpp)
add_executable(example_instance examples/atributes_usage.cpp)

# Linka a biblioteca ao executável
target_link_libraries(example_main PRIVATE mlcpppy)
target_link_libraries(example_instance PRIVATE mlcpppy)
13 changes: 13 additions & 0 deletions examples/atributes_usage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include "mlcpppy/instances/instances.h"

int main(int argc, char const *argv[])
{
// Exemplo de uso da classe atribute, instances e instance
Instance a(Attribute(1), Attribute(2.5), Attribute("Pedro"));
Instance b(Attribute(1), Attribute(2.5), Attribute("Pedro"));
Instance c(Attribute(1), Attribute(2.5), Attribute("Pedro"));
Instances matrix({a,b,c});
std::cout << matrix << std::endl;
return 0;
}
53 changes: 48 additions & 5 deletions include/mlcpppy/instances/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,65 @@
*/
#ifndef ATTRIBUTE_H
#define ATTRIBUTE_H

#include <string>
#include <variant>
#include <vector>
#include <iostream>

/**
* @brief Represents a single attribute that can hold multiple types of values.
*
* @note This class is still under development. Future features may include
* better type introspection, validation, and integration with Instances and ARFF loading.
*/
class Attribute
{
public:
using ValueType = std::variant<int, double, float, std::string>;
using ValueType = std::variant<int, double, float, std::string>; ///< Supported types for the attribute

/**
* @brief Constructs an Attribute with an int value.
* @param v The integer value to store.
*/
Attribute(int v) : value(v) {}

/**
* @brief Constructs an Attribute with a double value.
* @param v The double value to store.
*/
Attribute(double v) : value(v) {}

/**
* @brief Constructs an Attribute with a string value.
* @param v The string value to store.
*/
Attribute(const std::string& v) : value(v) {}
const ValueType& getValue() const { return value; }
~Attribute();

/**
* @brief Returns a constant reference to the stored value.
* @return The stored value as a ValueType.
*/
const ValueType& GetValue() const { return value; }

/**
* @brief Overloads the stream insertion operator to print the attribute value and type.
* @param os Output stream.
* @param a The Attribute object to print.
* @return Reference to the output stream.
*/
friend std::ostream& operator<<(std::ostream& os, const Attribute& a) {
std::visit([&os](auto&& arg) { os << arg << "(" << typeid(arg).name() << ")"; }, a.GetValue());
return os;
}

/**
* @brief Default destructor.
*/
~Attribute() = default;

private:
/* data */
ValueType value;
ValueType value; ///< Internal storage for the attribute's value
};

#endif // ATTRIBUTE_H
37 changes: 35 additions & 2 deletions include/mlcpppy/instances/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,47 @@
#define INSTANCE_H

#include <vector>
#include <iostream>
#include "attribute.h"

/**
* @brief Represents a single instance consisting of multiple Attribute objects.
*
* @note This class is still under development. Future features may include
* schema validation, type checking, and integration with ARFF datasets.
*/
class Instance
{
private:
std::vector<Attribute> values_instance_;
std::vector<Attribute> values_instance_; ///< Container for the attributes of this instance

public:
Instance(/* args */);
/**
* @brief Constructs an Instance with a variable number of Attribute arguments.
*
* @tparam Args Variadic template parameter representing Attribute types.
* @param args Attributes to include in this instance.
*/
template<typename ... Args>
Instance(Args... args) {
values_instance_ = {args...};
}

/**
* @brief Overloads the stream insertion operator to print all attributes in the instance.
* @param os Output stream.
* @param inst The Instance object to print.
* @return Reference to the output stream.
*/
friend std::ostream& operator<<(std::ostream& os, const Instance& inst) {
os << "[";
for (size_t i = 0; i < inst.values_instance_.size(); ++i) {
os << inst.values_instance_[i];
if (i != inst.values_instance_.size() - 1) os << ", "; // Comma between elements
}
os << "]";
return os;
}
};

#endif // INSTANCE_H
39 changes: 34 additions & 5 deletions include/mlcpppy/instances/instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,46 @@
#define INSTANCES_H

#include <vector>

#include "instance.h"

/**
* @brief Represents a collection of Instance objects, similar to a dataset in ARFF format.
*
* @note This class is still under development. Future features may include
* schema validation, type checking, and ARFF file loading.
*/
class Instances
{
private:
/* data */
std::vector<Instance> instances_data_;
std::vector<Instance> instances_data_; ///< Container for all Instance objects

public:
Instances(/* args */);
~Instances();
/**
* @brief Constructor that initializes the Instances collection.
* @param instances Vector of Instance objects to initialize the collection.
*/
Instances(std::vector<Instance> instances) : instances_data_(instances) {}

/**
* @brief Overloads the stream insertion operator to print all instances.
* @param os Output stream.
* @param instances The Instances object to print.
* @return Reference to the output stream.
*/
friend std::ostream& operator<<(std::ostream& os, const Instances& instances) {
os << "[";
for (size_t i = 0; i < instances.instances_data_.size(); ++i) {
os << instances.instances_data_[i];
if (i != instances.instances_data_.size() - 1) os << ", \n"; // Comma between elements
}
os << "]";
return os;
}

/**
* @brief Default destructor.
*/
~Instances() = default;
};

#endif // INSTANCES_H