mercredi 29 septembre 2021

Class's container get() member function usage vs copying

I have created a config class which loads configuration from a config YAML. I have created vector containers for each type

// Pseudo Code
class config
{
private:
    std::vector<std::string> c_name;

public:
    config(yaml_file_path)
    {
        // Handles reading from yaml and loading data to c_name container.
        load(yaml_file_path);
    }

    std::vector<std::string> get_name()
    {
        return c_name;
    }
};

I use this object in other class to get the name config.

class loadConfig 
{
    config cfg(yaml_file_path);
    std::vector<std::string> name = cfg.get_name();
    // Further use of vector name like checks.
}

Question : What would be better?(as code practice and execution time and/or memory space)

  1. Using get_name() function in various places in code. OR
  2. Copying value in container, as I have done?

Aucun commentaire:

Enregistrer un commentaire