diff --git a/CMakeLists.txt b/CMakeLists.txt index f743ae8..972b11d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/examples/atributes_usage.cpp b/examples/atributes_usage.cpp new file mode 100644 index 0000000..79bb9ee --- /dev/null +++ b/examples/atributes_usage.cpp @@ -0,0 +1,13 @@ +#include +#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; +} \ No newline at end of file diff --git a/include/mlcpppy/instances/attribute.h b/include/mlcpppy/instances/attribute.h index d99bd5c..adeacad 100644 --- a/include/mlcpppy/instances/attribute.h +++ b/include/mlcpppy/instances/attribute.h @@ -16,22 +16,65 @@ */ #ifndef ATTRIBUTE_H #define ATTRIBUTE_H + #include #include #include +#include +/** + * @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; + using ValueType = std::variant; ///< 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 \ No newline at end of file diff --git a/include/mlcpppy/instances/instance.h b/include/mlcpppy/instances/instance.h index b2fdc40..c0fece6 100644 --- a/include/mlcpppy/instances/instance.h +++ b/include/mlcpppy/instances/instance.h @@ -18,14 +18,47 @@ #define INSTANCE_H #include +#include #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 values_instance_; + std::vector 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 + 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 \ No newline at end of file diff --git a/include/mlcpppy/instances/instances.h b/include/mlcpppy/instances/instances.h index 4ff9d15..9d900c2 100644 --- a/include/mlcpppy/instances/instances.h +++ b/include/mlcpppy/instances/instances.h @@ -18,17 +18,46 @@ #define INSTANCES_H #include - #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 instances_data_; + std::vector 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 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 \ No newline at end of file