2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2005-06-16 01:11:29 +00:00
|
|
|
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
2001-12-27 19:54:36 +00:00
|
|
|
//
|
|
|
|
// See the file "license" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2006-03-19 00:46:04 +00:00
|
|
|
// $Id: PropsSet.hxx,v 1.14 2006-03-19 00:46:04 stephena Exp $
|
2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
#ifndef PROPERTIES_SET_HXX
|
|
|
|
#define PROPERTIES_SET_HXX
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2002-01-16 02:14:25 +00:00
|
|
|
#include <fstream>
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
#include "bspf.hxx"
|
|
|
|
|
2006-03-19 00:46:04 +00:00
|
|
|
class OSystem;
|
2002-01-08 17:11:32 +00:00
|
|
|
class Properties;
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
This class maintains a sorted collection of properties. The objects
|
|
|
|
are maintained in a binary search tree sorted by md5, since this is
|
|
|
|
the attribute most likely to be present in each entry in stella.pro
|
|
|
|
and least likely to change. A change in MD5 would mean a change in
|
|
|
|
the game rom image (essentially a different game) and this would
|
|
|
|
necessitate a new entry in the stella.pro file anyway.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2002-01-08 17:11:32 +00:00
|
|
|
@author Stephen Anthony
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
|
|
|
class PropertiesSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Create an empty properties set object using the md5 as the
|
|
|
|
key to the BST.
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2006-03-19 00:46:04 +00:00
|
|
|
PropertiesSet(OSystem* osystem);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
virtual ~PropertiesSet();
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
public:
|
2001-12-27 19:54:36 +00:00
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Get the property from the set with the given MD5.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param md5 The md5 of the property to get
|
|
|
|
@param properties The property with the given MD5, or the default
|
|
|
|
properties if not found
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2005-09-11 22:55:51 +00:00
|
|
|
void getMD5(const string& md5, Properties& properties);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2002-01-08 17:11:32 +00:00
|
|
|
/**
|
2002-01-16 02:14:25 +00:00
|
|
|
Load properties from the specified file. Use the given
|
2002-01-08 17:11:32 +00:00
|
|
|
defaults properties as the defaults for any properties loaded.
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param filename Full pathname of input file to use
|
2005-09-16 18:15:44 +00:00
|
|
|
@param save Indicates whether to set the 'save' tag for
|
|
|
|
these properties
|
2002-01-08 17:11:32 +00:00
|
|
|
*/
|
2005-09-16 18:15:44 +00:00
|
|
|
void load(const string& filename, bool save);
|
2002-01-16 02:14:25 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Save properties to the specified output stream
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param out The output stream to use
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2002-01-08 17:11:32 +00:00
|
|
|
void save(ostream& out);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the number of properties in the collection.
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@return The number of properties in the collection
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
|
|
|
uInt32 size() const;
|
|
|
|
|
2004-07-05 00:53:48 +00:00
|
|
|
/**
|
|
|
|
Prints the contents of the PropertiesSet as a flat file.
|
|
|
|
*/
|
|
|
|
void print();
|
|
|
|
|
2002-11-11 02:52:02 +00:00
|
|
|
/**
|
|
|
|
Merge the given properties into the collection.
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param properties The properties to merge
|
|
|
|
@param filename Full pathname of properties file to save
|
|
|
|
|
|
|
|
@return True on success, false on failure
|
|
|
|
Failure occurs if file couldn't be opened for writing
|
2002-11-11 02:52:02 +00:00
|
|
|
*/
|
2005-09-11 22:55:51 +00:00
|
|
|
bool merge(const Properties& properties, const string& filename);
|
2002-11-11 02:52:02 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Insert the properties into the set. If a duplicate is inserted
|
|
|
|
the old properties are overwritten with the new ones.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param properties The collection of properties
|
2005-09-16 18:15:44 +00:00
|
|
|
@param save Indicates whether to set the 'save' tag for
|
|
|
|
this property
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2005-10-19 00:59:51 +00:00
|
|
|
void insert(const Properties& properties, bool save = true);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct TreeNode {
|
|
|
|
Properties* props;
|
|
|
|
TreeNode* left;
|
|
|
|
TreeNode* right;
|
|
|
|
bool save;
|
|
|
|
};
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2002-01-08 17:11:32 +00:00
|
|
|
/**
|
|
|
|
Insert a node in the bst, keeping the tree sorted.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param node The current subroot of the tree
|
|
|
|
@param properties The collection of properties
|
2005-09-16 18:15:44 +00:00
|
|
|
@param save Indicates whether to set the 'save' tag for
|
|
|
|
this property
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2005-09-16 18:15:44 +00:00
|
|
|
void insertNode(TreeNode* &node, const Properties& properties, bool save);
|
2002-01-08 17:11:32 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Deletes a node from the bst. Does not preserve bst sorting.
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param node The current subroot of the tree
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2002-01-08 17:11:32 +00:00
|
|
|
void deleteNode(TreeNode *node);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
/**
|
2002-01-08 17:11:32 +00:00
|
|
|
Save current node properties to the specified output stream
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param out The output stream to use
|
|
|
|
@param node The current subroot of the tree
|
2001-12-27 19:54:36 +00:00
|
|
|
*/
|
2002-01-08 17:11:32 +00:00
|
|
|
void saveNode(ostream& out, TreeNode *node);
|
|
|
|
|
2004-07-05 00:53:48 +00:00
|
|
|
/**
|
|
|
|
Prints the current node properties
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
@param node The current subroot of the tree
|
2004-07-05 00:53:48 +00:00
|
|
|
*/
|
|
|
|
void printNode(TreeNode *node);
|
|
|
|
|
2005-09-11 22:55:51 +00:00
|
|
|
private:
|
2006-03-19 00:46:04 +00:00
|
|
|
// The parent system for this object
|
|
|
|
OSystem* myOSystem;
|
|
|
|
|
2002-01-08 17:11:32 +00:00
|
|
|
// The root of the BST
|
2002-11-11 02:52:02 +00:00
|
|
|
TreeNode* myRoot;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2002-01-08 17:11:32 +00:00
|
|
|
// The size of the properties bst (i.e. the number of properties in it)
|
|
|
|
uInt32 mySize;
|
2001-12-27 19:54:36 +00:00
|
|
|
};
|
2005-09-11 22:55:51 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
#endif
|