⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.h

📁 遗传算法的四个源程序和源代码
💻 H
字号:

/*
 * 
 * website: http://www.coolsoft-sd.com/
 * contact: support@coolsoft-sd.com
 *
 */

/*
 * Genetic Algorithm Library
 * Copyright (C) 2007-2008 Coolsoft Software Development
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#include <list>
#include <hash_map>
#include <fstream>
#include <string>

#pragma once

using namespace std;
using namespace stdext;

class Professor;
class StudentsGroup;
class Course;
class Room;
class CourseClass;

// Reads configration file and stores parsed objects
class Configuration
{

private:

	// Global instance
	static Configuration _instance;

public:

	// Returns reference to global instance
	inline static Configuration& GetInstance() { return _instance; }

private:

	// Parsed professors
	hash_map<int, Professor*> _professors;

	// Parsed student groups
	hash_map<int, StudentsGroup*> _studentGroups;

	// Parsed courses
	hash_map<int, Course*> _courses;

	// Parsed rooms
	hash_map<int, Room*> _rooms;

	// Parsed classes
	list<CourseClass*> _courseClasses;

	// Inidicate that configuration is not prsed yet
	bool _isEmpty;

public:

	// Initialize data
	Configuration() : _isEmpty(true) { }

	// Frees used resources
	~Configuration();

	// Parse file and store parsed object
	void ParseFile(char* fileName);

	// Returns pointer to professor with specified ID
	// If there is no professor with such ID method returns NULL
	inline Professor* GetProfessorById(int id)
	{ 
		hash_map<int, Professor*>::iterator it = _professors.find( id );
		return it != _professors.end() ? ( *it ).second : NULL;
	}

	// Returns number of parsed professors
	inline int GetNumberOfProfessors() const { return (int)_professors.size(); }

	// Returns pointer to student group with specified ID
	// If there is no student group with such ID method returns NULL
	inline StudentsGroup* GetStudentsGroupById(int id)
	{ 
		hash_map<int, StudentsGroup*>::iterator it = _studentGroups.find( id );
		return it != _studentGroups.end() ? ( *it ).second : NULL;
	}

	// Returns number of parsed student groups
	inline int GetNumberOfStudentGroups() const { return (int)_studentGroups.size(); }

	// Returns pointer to course with specified ID
	// If there is no course with such ID method returns NULL
	inline Course* GetCourseById(int id)
	{ 
		hash_map<int, Course*>::iterator it = _courses.find( id );
		return it != _courses.end() ? ( *it ).second : NULL;
	}

	inline int GetNumberOfCourses() const { return (int)_courses.size(); }

	// Returns pointer to room with specified ID
	// If there is no room with such ID method returns NULL
	inline Room* GetRoomById(int id)
	{ 
		hash_map<int, Room*>::iterator it = _rooms.find( id );
		return it != _rooms.end() ? ( *it ).second : NULL;
	}

	// Returns number of parsed rooms
	inline int GetNumberOfRooms() const { return (int)_rooms.size(); }

	// Returns reference to list of parsed classes
	inline const list<CourseClass*>& GetCourseClasses() const { return _courseClasses; }

	// Returns number of parsed classes
	inline int GetNumberOfCourseClasses() const { return (int)_courseClasses.size(); }

	// Returns TRUE if configuration is not parsed yet
	inline bool IsEmpty() const { return _isEmpty; }

private:

	// Reads professor's data from config file, makes object and returns pointer to it
	// Returns NULL if method cannot parse configuration data
	Professor* ParseProfessor(ifstream& file);

	// Reads professor's data from config file, makes object and returns pointer to it
	// Returns NULL if method cannot parse configuration data
	StudentsGroup* ParseStudentsGroup(ifstream& file);

	// Reads course's data from config file, makes object and returns pointer to it
	// Returns NULL if method cannot parse configuration data
	Course* ParseCourse(ifstream& file);

	// Reads rooms's data from config file, makes object and returns pointer to it
	// Returns NULL if method cannot parse configuration data
	Room* ParseRoom(ifstream& file);

	// Reads class' data from config file, makes object and returns pointer to it
	// Returns NULL if method cannot parse configuration data
	CourseClass* ParseCourseClass(ifstream& file);

	// Reads one line (key - value pair) from configuration file
	bool GetConfigBlockLine(ifstream& file, string& key, string& value);

	// Removes blank characters from beginning and end of string
	string& TrimString(string& str);

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -