<commit_before>/*===============================================================================================*/
// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*===============================================================================================*/

extern crate serde;

use ::resource::config::ConfigLoader;
use ::resource::plugin::PluginLoader;

use self::serde::{Deserialize, Serialize};

use std::cell::RefCell;
use std::rc::Rc;

/*===============================================================================================*/
/*------RESOURCE MANAGER STRUCT------------------------------------------------------------------*/
/*===============================================================================================*/

/// Interface for resource loading and management.
pub struct ResourceManager {

    // Private
    _cfg_dir: String,
    _res_dir: String,
    _bin_dir: String,

    _config_loader: Rc<RefCell<ConfigLoader>>,
    _plugin_loader: Rc<RefCell<PluginLoader>>,
}

/*===============================================================================================*/
/*------RESOURCE MANAGER PUBLIC METHODS----------------------------------------------------------*/
/*===============================================================================================*/

impl ResourceManager {

    /// Initializes the Resource Manager.
    pub fn init (&mut self) {
        self._plugin_loader.borrow_mut ().init (self);
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Loads a config file.
    pub fn load_config<T: Deserialize> (&self, config_name: &str) -> Result<T, ()> {
        self._config_loader.borrow ().load_config::<T> (&self._cfg_dir, config_name)
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Saves a config file.
    pub fn save_config<T: Serialize> (&self, config_name: &str, config_data: &T) -> Result<(), ()> {
        self._config_loader.borrow ().save_config::<T> (&self._cfg_dir, config_name, config_data)
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Returns a pointer to the config loader instance.
    pub unsafe fn get_config_loader_raw (&self) -> Rc<RefCell<ConfigLoader>> {
        self._config_loader.clone ()
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Returns a pointer to the plugin loader instance.
    pub unsafe fn get_plugin_loader_raw (&self) -> Rc<RefCell<PluginLoader>> {
        self._plugin_loader.clone ()
    }

/*===============================================================================================*/
/*------RESOURCE MANAGER PUBLIC STATIC METHODS---------------------------------------------------*/
/*===============================================================================================*/

    /// Create a new instance of the Resource Manager.
    pub fn new () -> ResourceManager {

        ResourceManager {

            _cfg_dir: "cfg/".to_string (),
            _res_dir: "res/".to_string (),
            _bin_dir: "bin/".to_string (),
            _config_loader: Rc::new (RefCell::new (ConfigLoader {})),<commit_msg>Made directory variables public<commit_after>/*===============================================================================================*/
// Copyright 2016 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*===============================================================================================*/

extern crate serde;

use ::resource::config::ConfigLoader;
use ::resource::plugin::PluginLoader;

use self::serde::{Deserialize, Serialize};

use std::cell::RefCell;
use std::rc::Rc;

/*===============================================================================================*/
/*------RESOURCE MANAGER STRUCT------------------------------------------------------------------*/
/*===============================================================================================*/

/// Interface for resource loading and management.
pub struct ResourceManager {

    // Public
    /// The config directory.
    pub cfg_dir: String,
    /// The resource direcotry.
    pub res_dir: String,
    /// The binary directory.
    pub bin_dir: String,
    /// The plugin directory.
    pub plug_dir: String,

    _config_loader: Rc<RefCell<ConfigLoader>>,
    _plugin_loader: Rc<RefCell<PluginLoader>>,
}

/*===============================================================================================*/
/*------RESOURCE MANAGER PUBLIC METHODS----------------------------------------------------------*/
/*===============================================================================================*/

impl ResourceManager {

    /// Initializes the Resource Manager.
    pub fn init (&mut self) {
        self._plugin_loader.borrow_mut ().init (self);
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Loads a config file.
    pub fn load_config<T: Deserialize> (&self, config_name: &str) -> Result<T, ()> {
        self._config_loader.borrow ().load_config::<T> (&self.cfg_dir, config_name)
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Saves a config file.
    pub fn save_config<T: Serialize> (&self, config_name: &str, config_data: &T) -> Result<(), ()> {
        self._config_loader.borrow ().save_config::<T> (&self.cfg_dir, config_name, config_data)
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Returns a pointer to the config loader instance.
    pub unsafe fn get_config_loader_raw (&self) -> Rc<RefCell<ConfigLoader>> {
        self._config_loader.clone ()
    }

/*-----------------------------------------------------------------------------------------------*/

    /// Returns a pointer to the plugin loader instance.
    pub unsafe fn get_plugin_loader_raw (&self) -> Rc<RefCell<PluginLoader>> {
        self._plugin_loader.clone ()
    }

/*===============================================================================================*/
/*------RESOURCE MANAGER PUBLIC STATIC METHODS---------------------------------------------------*/
/*===============================================================================================*/

    /// Create a new instance of the Resource Manager.
    pub fn new () -> ResourceManager {

        ResourceManager {

            cfg_dir: "cfg/".to_string (),
            res_dir: "res/".to_string (),
            bin_dir: "bin/".to_string (),
            plug_dir: "bin/plugins/".to_string (),
            _config_loader: Rc::new (RefCell::new (ConfigLoader {})),
{'fraction_non_alphanumeric': 0.43039736775499876, 'fraction_numerical': 0.0020248038471273096, 'mean_word_length': 2.1815619967793882, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3376347', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1645, 'n_words': 483}