[Scummvm-cvs-logs] SF.net SVN: scummvm: [27852] scummex/branches/gsoc2007-gameresbrowser/src
zbychs at users.sourceforge.net
zbychs at users.sourceforge.net
Mon Jul 2 15:36:56 CEST 2007
Revision: 27852
http://scummvm.svn.sourceforge.net/scummvm/?rev=27852&view=rev
Author: zbychs
Date: 2007-07-02 06:36:53 -0700 (Mon, 02 Jul 2007)
Log Message:
-----------
Added draft of Linux Makefile. Compiles on Fedora 7, gcc 4.1, wxW 2.8.
Modified Paths:
--------------
scummex/branches/gsoc2007-gameresbrowser/src/core/debugmem.h
scummex/branches/gsoc2007-gameresbrowser/src/core/ochain.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h
scummex/branches/gsoc2007-gameresbrowser/src/core/rcobject.h
scummex/branches/gsoc2007-gameresbrowser/src/core/treealgos.h
scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp
scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp
scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.h
scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.cpp
scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/BMPParser.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/scummsys.h
Removed Paths:
-------------
scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.cpp
scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.h
scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.wxform
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/array.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.cpp
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/fs.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/func.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hash-str.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.cpp
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.cpp
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/util.h
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/debugmem.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/debugmem.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/debugmem.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -40,4 +40,4 @@
#endif /* _MSC_VER, _DEBUG */
-#endif /* ZZ_DEBUG_H */
\ No newline at end of file
+#endif /* ZZ_DEBUG_H */
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/ochain.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/ochain.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/ochain.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -13,6 +13,7 @@
#include <functional>
#include <iostream>
+#include <algorithm>
#include "debugmem.h"
@@ -365,6 +366,15 @@
}
};
+//have to be on top-level, cause GCC complained when they were contained in a Util class
+typedef std::pair<BObject*, int> ocVisitRanks_the_pair;
+bool ocVisitRanks_compare(const ocVisitRanks_the_pair& p0, const ocVisitRanks_the_pair& p1) {
+ return p0.second < p1.second;
+}
+BObject* ocVisitRanks_transform(const ocVisitRanks_the_pair& p) {
+ return p.first;
+}
+
//functor for computing ranks of the nodes in the DAG
struct ocVisitRanks {
typedef std::map<BObject*, int> rank_map;
@@ -394,17 +404,12 @@
typedef std::pair<BObject*, int> the_pair;
typedef std::vector<the_pair> unrank_vec;
unrank_vec unranks( _ranks.begin(), _ranks.end() );
- struct Util {
- bool operator()(const the_pair& p0, const the_pair& p1) {
- return p0.second < p1.second;
- }
- BObject* operator()(const the_pair& p) {
- return p.first;
- }
- };
- std::sort(unranks.begin(), unranks.end(), Util());
+
+ using namespace std;
+
+ std::sort(unranks.begin(), unranks.end(), ocVisitRanks_compare);
objs.resize(unranks.size());
- std::transform(unranks.begin(), unranks.end(), objs.begin(), Util());
+ std::transform(unranks.begin(), unranks.end(), objs.begin(), ocVisitRanks_transform);
}
};
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -112,61 +112,7 @@
static bool dummy = (descs.shared = false); \
return descs; \
}
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Templates for use with PIN_DESC and SLOT_DESC macros.
-// They are only to force the compiler to guess types from the parameters,
-// so that they don't have to be explicitly written as macro parameters.
-// (Actually, only 'I' would have to written explicitly; 'flags' and 'Irel' too,
-// but those two are not guessed anyway.)
-// ISup is used here in two places - it's on purpose, for type safety.
-// (Without this template it wouldn't be type safe.)
-template<int flags, typename I, typename T, typename ISup>
-PinSlotDesc* makePinDesc(char* name, Pin<I>* T::* pin, ISup* (T::* getFun)(),
- void (T::* relFun)(ISup*) ) {
- return
- makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
- I::static_GUID(),
- flags,
- accessPin(pin),
- makePin<flags>(
- pin,
- std::mem_fun(getFun),
- cast2nd_binary<I*>(std::mem_fun(relFun))
- )
- );
-}
-
-//can turn into a macro to allow for other release() function names
-template<int flags, typename Irel, typename I, typename T, typename ISup>
-PinSlotDesc* makePinDesc(char* name, Pin<I>* T::* pin, ISup* (T::* getFun)() ) {
- return
- makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
- I::static_GUID(),
- flags,
- accessPin(pin),
- makePin<flags>(
- pin,
- std::mem_fun(getFun),
- binary_unary2nd<BObject*>(
- cast1st_unary<I*>( std::mem_fun(&Irel::release) )
- )
- )
- );
-}
-
-template<int flags, typename I, typename T>
-PinSlotDesc* makeSlotDesc(char* name, Slot<I>* T::* slot) {
- return
- makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
- I::static_GUID(),
- flags,
- accessSlot(slot),
- makeSlot<flags>(slot)
- );
-}
-
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Pin and Slot makers and accessors
@@ -223,10 +169,10 @@
return SlotMaker<flags,I,T>(_slot);
}
-template<typename I, typename T, template<typename I2> class PS>
+template<typename I, class T, template<typename I2> class PS>
struct PinSlotAccessor {
- typename PS<I>* T::*pin;
- PinSlotAccessor(typename PS<I>* T::*_pin)
+ PS<I>* T::*pin;
+ PinSlotAccessor(PS<I>* T::*_pin)
: pin(_pin) {}
PinSlotType* operator()(BObject* that) const
{
@@ -246,7 +192,62 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+// Templates for use with PIN_DESC and SLOT_DESC macros.
+// They are only to force the compiler to guess types from the parameters,
+// so that they don't have to be explicitly written as macro parameters.
+// (Actually, only 'I' would have to written explicitly; 'flags' and 'Irel' too,
+// but those two are not guessed anyway.)
+// ISup is used here in two places - it's on purpose, for type safety.
+// (Without this template it wouldn't be type safe.)
+template<int flags, typename I, typename T, typename ISup>
+PinSlotDesc* makePinDesc(char* name, Pin<I>* T::* pin, ISup* (T::* getFun)(),
+ void (T::* relFun)(ISup*) ) {
+ return
+ makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
+ I::static_GUID(),
+ flags,
+ accessPin(pin),
+ makePin<flags>(
+ pin,
+ std::mem_fun(getFun),
+ cast2nd_binary<I*>(std::mem_fun(relFun))
+ )
+ );
+}
+
+//can turn into a macro to allow for other release() function names
+template<int flags, typename Irel, typename I, typename T, typename ISup>
+PinSlotDesc* makePinDesc(char* name, Pin<I>* T::* pin, ISup* (T::* getFun)() ) {
+ return
+ makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
+ I::static_GUID(),
+ flags,
+ accessPin(pin),
+ makePin<flags>(
+ pin,
+ std::mem_fun(getFun),
+ binary_unary2nd<BObject*>(
+ cast1st_unary<I*>( std::mem_fun(&Irel::release) )
+ )
+ )
+ );
+}
+
+template<int flags, typename I, typename T>
+PinSlotDesc* makeSlotDesc(char* name, Slot<I>* T::* slot) {
+ return
+ makePinSlotDesc(std::string(typeid(T).name()) + "::" + name,
+ I::static_GUID(),
+ flags,
+ accessSlot(slot),
+ makeSlot<flags>(slot)
+ );
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
} // namespace Browser
#endif /* ZZ_PINSLOT_DETAIL_H */
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/rcobject.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/rcobject.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/rcobject.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -4,6 +4,8 @@
#ifndef ZZ_MEYERS_H
#define ZZ_MEYERS_H
+#include <functional> //for less<>
+
namespace Browser {
/******************************************************************************
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/treealgos.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/treealgos.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/treealgos.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -57,7 +57,7 @@
std::stack<int> levels;
virtual bool empty() {
- return q.empty();
+ return s.empty();
}
virtual void push(const T& _val, int _level) {
s.push(_val);
@@ -84,16 +84,6 @@
SKIP, //skip expansion of this node
};
-template<typename Node, typename VisitFun, typename ExpandFun>
-bool bfs(Node initial, VisitFun& visitFun, ExpandFun& expandFun) {
- return tree_search< bfs_fringe<Node> >(initial, visitFun, expandFun);
-}
-
-template<typename Node, typename VisitFun, typename ExpandFun>
-bool dfs(Node initial, VisitFun& visitFun, ExpandFun& expandFun) {
- return tree_search< dfs_fringe<Node> >(initial, visitFun, expandFun);
-}
-
template<typename Fringe, typename Node, typename VisitFun, typename ExpandFun>
bool tree_search(Node initial, VisitFun& visitFun, ExpandFun& expandFun)
{
@@ -116,6 +106,16 @@
}
}
+template<typename Node, typename VisitFun, typename ExpandFun>
+bool bfs(Node initial, VisitFun& visitFun, ExpandFun& expandFun) {
+ return tree_search< bfs_fringe<Node> >(initial, visitFun, expandFun);
+}
+
+template<typename Node, typename VisitFun, typename ExpandFun>
+bool dfs(Node initial, VisitFun& visitFun, ExpandFun& expandFun) {
+ return tree_search< dfs_fringe<Node> >(initial, visitFun, expandFun);
+}
+
} // namespace tree_algos
/////////////////////////////////////////////////////////////////////////////
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,114 +0,0 @@
-//---------------------------------------------------------------------------
-//
-// Name: BrowserDlg.cpp
-// Author: RootBoot
-// Created: 2007-06-25 17:22:36
-// Description: BrowserDlg class implementation
-//
-//---------------------------------------------------------------------------
-
-#include "wx/wxprec.h"
-
-#if defined(__BORLANDC__)
-#pragma hdrstop
-#endif
-
-#include "BrowserDlg.h"
-
-//Do not add custom headers
-//wxDev-C++ designer will remove them
-////Header Include Start
-////Header Include End
-
-#include "DiskFileProvider.h"
-#include "BMPParser.h"
-#include "ImagePresenter.h"
-
-#include <iostream>
-
-//----------------------------------------------------------------------------
-// BrowserDlg
-//----------------------------------------------------------------------------
-//Add Custom Events only in the appropriate block.
-//Code added in other places will be removed by wxDev-C++
-////Event Table Start
-BEGIN_EVENT_TABLE(BrowserDlg,wxDialog)
- ////Manual Code Start
- ////Manual Code End
-
- EVT_CLOSE(BrowserDlg::OnClose)
-END_EVENT_TABLE()
-////Event Table End
-
-BrowserDlg::BrowserDlg(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
-: wxDialog(parent, id, title, position, size, style)
-{
- CreateGUIControls();
-
- using namespace Browser;
-
- RCPtr<DiskFileProvider> prov(new DiskFileProvider("data\\lalka.bmp"));
- RCPtr<BMPParser> bmp(new BMPParser());
- RCPtr<ImagePresenter> pres(new ImagePresenter(imagePanel));
-
- _chain = new ObjectChain();
-
- _chain->addObject(prov);
- _chain->addObject(bmp);
- _chain->addObject(pres);
-
- bool fi = _chain->connect(prov, bmp, IFile::static_GUID() );
- std::cout << "FileProvider -> BMPFileType: " << (fi ? "OK" : "FAILED") << std::endl;
-
- bool bi = _chain->connect(bmp, pres, IImage::static_GUID() );
- std::cout << "BMPFileType -> BMPPresenter: " << (bi ? "OK" : "FAILED") << std::endl;
-
- std::cout << "Attempting to render bitmap:" << std::endl;
- pres->drawImage();
- std::cout << "Done" << std::endl;
-}
-
-BrowserDlg::~BrowserDlg()
-{
- delete _chain;
-}
-
-void BrowserDlg::CreateGUIControls()
-{
- //Do not add custom code between
- //GUI Items Creation Start and GUI Items Creation End.
- //wxDev-C++ designer will remove them.
- //Add the custom code before or after the blocks
- ////GUI Items Creation Start
-
- WxSplitterWindow1 = new wxSplitterWindow(this, ID_WXSPLITTERWINDOW1, wxPoint(0,0), wxSize(549,475));
- WxSplitterWindow1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
-
- WxTreeCtrl1 = new wxTreeCtrl(WxSplitterWindow1, ID_WXTREECTRL1, wxPoint(5,5), wxSize(217,465), wxTR_HAS_BUTTONS);
- WxTreeCtrl1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
-
- WxPanel1 = new wxPanel(WxSplitterWindow1, ID_WXPANEL1, wxPoint(232,7), wxSize(302,460));
- WxPanel1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
-
- WxSplitterWindow1->SplitVertically(WxTreeCtrl1,WxPanel1,121);
-
- SetTitle(wxT("Browser"));
- SetIcon(wxNullIcon);
- SetSize(8,8,557,502);
- Center();
-
- ////GUI Items Creation End
-}
-
-void BrowserDlg::OnClose(wxCloseEvent& /*event*/)
-{
- Destroy();
-}
-
-/*
- * WxTreeCtrl1BeginDrag
- */
-void BrowserDlg::WxTreeCtrl1BeginDrag(wxTreeEvent& event)
-{
- // insert your code here
-}
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,83 +0,0 @@
-//---------------------------------------------------------------------------
-//
-// Name: BrowserDlg.h
-// Author: RootBoot
-// Created: 2007-06-25 17:22:36
-// Description: BrowserDlg class declaration
-//
-//---------------------------------------------------------------------------
-
-#ifndef __BROWSERDLG_h__
-#define __BROWSERDLG_h__
-
-#include "wx/wxprec.h"
-
-#if defined(__BORLANDC__)
-#pragma hdrstop
-#endif
-
-#ifndef WX_PRECOMP
- #include <wx/wx.h>
- #include <wx/dialog.h>
-#endif
-
-//Do not add custom headers between
-//Header Include Start and Header Include End.
-//wxDev-C++ designer will remove them. Add custom headers after the block.
-////Header Include Start
-#include <wx/panel.h>
-#include <wx/treectrl.h>
-#include <wx/splitter.h>
-////Header Include End
-
-#include "ochain.h"
-
-////Dialog Style Start
-#undef BrowserDlg_STYLE
-#define BrowserDlg_STYLE wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxTHICK_FRAME | wxDIALOG_NO_PARENT | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX
-////Dialog Style End
-
-class BrowserDlg : public wxDialog
-{
- private:
- DECLARE_EVENT_TABLE();
-
- public:
- BrowserDlg(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("Browser"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = BrowserDlg_STYLE);
- virtual ~BrowserDlg();
- void WxTreeCtrl1BeginDrag(wxTreeEvent& event);
-
- private:
- //Do not add custom control declarations between
- //GUI Control Declaration Start and GUI Control Declaration End.
- //wxDev-C++ will remove them. Add custom code after the block.
- ////GUI Control Declaration Start
- wxPanel *WxPanel1;
- wxTreeCtrl *WxTreeCtrl1;
- wxSplitterWindow *WxSplitterWindow1;
- ////GUI Control Declaration End
-
- private:
- //Note: if you receive any error with these enum IDs, then you need to
- //change your old form code that are based on the #define control IDs.
- //#defines may replace a numeric value for the enum names.
- //Try copy and pasting the below block in your old form header files.
- enum
- {
- ////GUI Enum Control ID Start
- ID_WXPANEL1 = 1018,
- ID_WXTREECTRL1 = 1017,
- ID_WXSPLITTERWINDOW1 = 1015,
- ////GUI Enum Control ID End
- ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
- };
-
- private:
- void OnClose(wxCloseEvent& event);
- void CreateGUIControls();
-
- private:
- Browser::ObjectChain* _chain;
-};
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.wxform
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.wxform 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/BrowserDlg.wxform 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,89 +0,0 @@
-object frmNewForm: TfrmNewForm
- Left = 8
- Top = 8
- AutoScroll = False
- BorderIcons = [biSystemMenu, biMinimize]
- Caption = 'Browser'
- ClientHeight = 475
- ClientWidth = 549
- Color = clBtnFace
- OldCreateOrder = True
- PopupMenu = MainForm.DesignerPopup
- Visible = True
- OnCloseQuery = FormCloseQuery
- OnCreate = FormCreate
- OnDestroy = FormDestroy
- OnResize = FormResize
- EVT_CLOSE = 'OnClose'
- Wx_ICON.Data = {07544269746D617000000000}
- Wx_Name = 'BrowserDlg'
- Wx_IDName = 'ID_DIALOG1'
- Wx_IDValue = 1000
- Wx_Class = 'wxDialog'
- Wx_Center = True
- Wx_Hidden = False
- Wx_SizeToContents = True
- Wx_GeneralStyle = []
- Wx_DialogStyle = [wxCAPTION, wxRESIZE_BORDER, wxSYSTEM_MENU, wxTHICK_FRAME, wxDIALOG_NO_PARENT, wxMINIMIZE_BOX, wxMAXIMIZE_BOX, wxCLOSE_BOX]
- Wx_Border = 0
- Wx_BorderAlignment = []
- PixelsPerInch = 96
- TextHeight = 13
- object WxSplitterWindow1: TWxSplitterWindow
- Left = 0
- Top = 0
- Width = 549
- Height = 475
- Align = alClient
- TabOrder = 0
- Wx_Class = 'wxSplitterWindow'
- Wx_ControlOrientation = wxControlVertical
- Wx_EventList.Strings = (
- 'EVT_SPLITTER_SASH_POS_CHANGING : OnSashPosChanging'
- 'EVT_SPLITTER_SASH_POS_CHANGED : OnSashPosChanged'
- 'EVT_SPLITTER_UNSPLIT : OnUnSplit'
- 'EVT_SPLITTER_DCLICK : OnDoubleClick'
- 'EVT_UPDATE_UI : OnUpdateUI')
- Wx_IDName = 'ID_WXSPLITTERWINDOW1'
- Wx_IDValue = 1015
- Wx_SashPosition = 121
- Wx_GeneralStyle = []
- Wx_SplitterStyle = []
- Wx_Border = 0
- object WxTreeCtrl1: TWxTreeCtrl
- Left = 5
- Top = 5
- Width = 217
- Height = 465
- Indent = 19
- TabOrder = 0
- Wx_BGColor = clBlack
- Wx_Class = 'wxTreeCtrl'
- Wx_ControlOrientation = wxControlHorizontal
- Wx_FGColor = clBlack
- Wx_GeneralStyle = []
- Wx_Hidden = False
- Wx_IDName = 'ID_WXTREECTRL1'
- Wx_IDValue = 1017
- Wx_TreeviewStyle = [wxTR_HAS_BUTTONS]
- end
- object WxPanel1: TWxPanel
- Left = 232
- Top = 7
- Width = 302
- Height = 460
- TabOrder = 1
- Wx_BKColor = clBlack
- Wx_Class = 'wxPanel'
- Wx_ControlOrientation = wxControlHorizontal
- Wx_Default = False
- Wx_EventList.Strings = (
- 'EVT_UPDATE_UI:OnUpdateUI')
- Wx_FGColor = clBlack
- Wx_GeneralStyle = []
- Wx_Hidden = False
- Wx_IDName = 'ID_WXPANEL1'
- Wx_IDValue = 1018
- end
- end
-end
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/Test1.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -50,9 +50,9 @@
new VirtualNodeItemData( rootDir.get() ) );
- rootDir->addFile("Doll", "data\\lalka.bmp");
- rootDir->addFile("Dog", "data\\pies.bmp");
- rootDir->addFile("Foxes", "data\\lisy.bmp");
+ rootDir->addFile("Doll", "data/lalka.bmp");
+ rootDir->addFile("Dog", "data/pies.bmp");
+ rootDir->addFile("Foxes", "data/lisy.bmp");
ObjectRegistry::get()->registerPlugin( &getTest1Plugin, true );
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -146,7 +146,9 @@
IFile* ifile = *i;
wxTreeItemId kidTreeItem = ExplorationTree::_getTree()->
- AppendItem(parent->getTreeItem(), ifile->getName().c_str(), -1, -1, NULL);
+ AppendItem(parent->getTreeItem(),
+ wxString(ifile->getName().c_str(), wxConvUTF8),
+ -1, -1, NULL);
RCPtr<VirtualFile> virtualFile( new VirtualFile(kidTreeItem, ifile) );
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/VirtualNode.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -95,7 +95,7 @@
VirtualNode* getParent();
INodeProviderImpl* getNodeProviderImpl();
- void VirtualNode::releaseNodeProviderImpl(INodeProviderImpl* iface);
+ void releaseNodeProviderImpl(INodeProviderImpl* iface);
};
/////////////////////////////////////////////////////////////////////////////
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -6,17 +6,18 @@
#pragma hdrstop
#endif
+#ifndef _MSC_VER
-#include <windows.h>
+void RedirectIOToConsole() {
+}
-#include <stdio.h>
+#else
+#include <windows.h>
+#include <stdio.h>
#include <fcntl.h>
-
#include <io.h>
-
#include <iostream>
-
#include <fstream>
#ifndef _USE_OLD_IOSTREAMS
@@ -29,8 +30,6 @@
static const WORD MAX_CONSOLE_LINES = 500;
-#ifdef _DEBUG
-
void RedirectIOToConsole()
{
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/guicon.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,15 +1,10 @@
//Listing 2: guicon.h -- Interface to console redirection function
#ifndef __GUICON_H__
-
#define __GUICON_H__
-#ifdef _DEBUG
-
void RedirectIOToConsole();
#endif
-#endif
-
/* End of File */
Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/BMPParser.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/BMPParser.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/BMPParser.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -6,6 +6,8 @@
#include "stdafx.h"
+#include "wx/image.h"
+
#include "DiskFileProvider.h" //for now - just for IFile and SeekableReadStream
namespace Browser {
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/array.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/array.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/array.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,180 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/array.h $
- * $Id: array.h 26115 2007-03-12 22:34:29Z fingolfin $
- */
-
-#ifndef COMMON_ARRAY_H
-#define COMMON_ARRAY_H
-
-#include "common/scummsys.h"
-
-namespace Common {
-
-template <class T>
-class Array {
-protected:
- int _capacity;
- int _size;
- T *_data;
-
-public:
- typedef T *iterator;
- typedef const T *const_iterator;
-
-public:
- Array() : _capacity(0), _size(0), _data(0) {}
- Array(const Array<T>& array) : _capacity(0), _size(0), _data(0) {
- _size = array._size;
- _capacity = _size + 32;
- _data = new T[_capacity];
- for (int i = 0; i < _size; i++)
- _data[i] = array._data[i];
- }
-
- ~Array() {
- if (_data)
- delete [] _data;
- }
-
- void push_back(const T& element) {
- ensureCapacity(_size + 1);
- _data[_size++] = element;
- }
-
- void push_back(const Array<T>& array) {
- ensureCapacity(_size + array._size);
- for (int i = 0; i < array._size; i++)
- _data[_size++] = array._data[i];
- }
-
- void insert_at(int idx, const T& element) {
- assert(idx >= 0 && idx <= _size);
- ensureCapacity(_size + 1);
- // The following loop is not efficient if you can just memcpy things around.
- // e.g. if you have a list of ints. But for real objects (String...), memcpy
- // usually isn't correct (specifically, for any class which has a non-default
- // copy behaviour. E.g. the String class uses a refCounter which has to be
- // updated whenever a String is copied.
- for (int i = _size; i > idx; i--) {
- _data[i] = _data[i-1];
- }
- _data[idx] = element;
- _size++;
- }
-
- T remove_at(int idx) {
- assert(idx >= 0 && idx < _size);
- T tmp = _data[idx];
- for (int i = idx; i < _size - 1; i++)
- _data[i] = _data[i+1];
- _size--;
- return tmp;
- }
-
- // TODO: insert, remove, ...
-
- T& operator [](int idx) {
- assert(idx >= 0 && idx < _size);
- return _data[idx];
- }
-
- const T& operator [](int idx) const {
- assert(idx >= 0 && idx < _size);
- return _data[idx];
- }
-
- Array<T>& operator =(const Array<T>& array) {
- if (this == &array)
- return *this;
-
- if (_data)
- delete [] _data;
- _size = array._size;
- _capacity = _size + 32;
- _data = new T[_capacity];
- for (int i = 0; i < _size; i++)
- _data[i] = array._data[i];
-
- return *this;
- }
-
- uint size() const {
- return _size;
- }
-
- void clear() {
- if (_data) {
- delete [] _data;
- _data = 0;
- }
- _size = 0;
- _capacity = 0;
- }
-
- bool empty() const {
- return (_size == 0);
- }
-
-
- iterator begin() {
- return _data;
- }
-
- iterator end() {
- return _data + _size;
- }
-
- const_iterator begin() const {
- return _data;
- }
-
- const_iterator end() const {
- return _data + _size;
- }
-
- bool contains(const T &key) const {
- for (const_iterator i = begin(); i != end(); ++i) {
- if (*i == key)
- return true;
- }
- return false;
- }
-
-
-protected:
- void ensureCapacity(int new_len) {
- if (new_len <= _capacity)
- return;
-
- T *old_data = _data;
- _capacity = new_len + 32;
- _data = new T[_capacity];
-
- if (old_data) {
- // Copy old data
- for (int i = 0; i < _size; i++)
- _data[i] = old_data[i];
- delete [] old_data;
- }
- }
-};
-
-} // End of namespace Common
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,532 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/file.cpp $
- * $Id: file.cpp 26394 2007-04-06 18:34:53Z agent-q $
- *
- */
-
-#include "common/file.h"
-#include "common/fs.h"
-#include "common/hashmap.h"
-#include "common/util.h"
-#include "common/hash-str.h"
-
-#ifdef MACOSX
-#include "CoreFoundation/CoreFoundation.h"
-#endif
-
-#ifdef __PLAYSTATION2__
- // for those replaced fopen/fread/etc functions
- typedef unsigned long uint64;
- typedef signed long int64;
- #include "backends/platform/ps2/fileio.h"
-
- #define fopen(a, b) ps2_fopen(a, b)
- #define fclose(a) ps2_fclose(a)
- #define fseek(a, b, c) ps2_fseek(a, b, c)
- #define ftell(a) ps2_ftell(a)
- #define feof(a) ps2_feof(a)
- #define fread(a, b, c, d) ps2_fread(a, b, c, d)
- #define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d)
-
- //#define fprintf ps2_fprintf // used in common/util.cpp
- //#define fflush(a) ps2_fflush(a) // used in common/util.cpp
-
- //#define fgetc(a) ps2_fgetc(a) // not used
- //#define fgets(a, b, c) ps2_fgets(a, b, c) // not used
- //#define fputc(a, b) ps2_fputc(a, b) // not used
- //#define fputs(a, b) ps2_fputs(a, b) // not used
-
- //#define fsize(a) ps2_fsize(a) // not used -- and it is not a standard function either
-#endif
-
-#ifdef __DS__
-
- // These functions replease the standard library functions of the same name.
- // As this header is included after the standard one, I have the chance to #define
- // all of these to my own code.
- //
- // A #define is the only way, as redefinig the functions would cause linker errors.
-
- // These functions need to be #undef'ed, as their original definition
- // in devkitarm is done with #includes (ugh!)
- #undef feof
- #undef clearerr
- //#undef getc
- //#undef ferror
-
-
- //void std_fprintf(FILE* handle, const char* fmt, ...); // used in common/util.cpp
- //void std_fflush(FILE* handle); // used in common/util.cpp
-
- //char* std_fgets(char* str, int size, FILE* file); // not used
- //int std_getc(FILE* handle); // not used
- //char* std_getcwd(char* dir, int dunno); // not used
- //void std_cwd(char* dir); // not used
- //int std_ferror(FILE* handle); // not used
-
- // Only functions used in the ScummVM source have been defined here!
- #define fopen(name, mode) DS::std_fopen(name, mode)
- #define fclose(handle) DS::std_fclose(handle)
- #define fread(ptr, size, items, file) DS::std_fread(ptr, size, items, file)
- #define fwrite(ptr, size, items, file) DS::std_fwrite(ptr, size, items, file)
- #define feof(handle) DS::std_feof(handle)
- #define ftell(handle) DS::std_ftell(handle)
- #define fseek(handle, offset, whence) DS::std_fseek(handle, offset, whence)
- #define clearerr(handle) DS::std_clearerr(handle)
-
- //#define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
-
- //#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
- //#define fflush(file) DS::std_fflush(file) // used in common/util.cpp
-
- //#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used
- //#define getc(handle) DS::std_getc(handle) // not used
- //#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) // not used
- //#define ferror(handle) DS::std_ferror(handle) // not used
-
-#endif
-
-#ifdef __SYMBIAN32__
- #undef feof
- #undef clearerr
-
- #define FILE void
-
- FILE* symbian_fopen(const char* name, const char* mode);
- void symbian_fclose(FILE* handle);
- size_t symbian_fread(const void* ptr, size_t size, size_t numItems, FILE* handle);
- size_t symbian_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle);
- bool symbian_feof(FILE* handle);
- long int symbian_ftell(FILE* handle);
- int symbian_fseek(FILE* handle, long int offset, int whence);
- void symbian_clearerr(FILE* handle);
-
- // Only functions used in the ScummVM source have been defined here!
- #define fopen(name, mode) symbian_fopen(name, mode)
- #define fclose(handle) symbian_fclose(handle)
- #define fread(ptr, size, items, file) symbian_fread(ptr, size, items, file)
- #define fwrite(ptr, size, items, file) symbian_fwrite(ptr, size, items, file)
- #define feof(handle) symbian_feof(handle)
- #define ftell(handle) symbian_ftell(handle)
- #define fseek(handle, offset, whence) symbian_fseek(handle, offset, whence)
- #define clearerr(handle) symbian_clearerr(handle)
-#endif
-
-namespace Common {
-
-typedef HashMap<String, int, CaseSensitiveString_Hash, CaseSensitiveString_EqualTo> StringIntMap;
-
-// The following two objects could be turned into static members of class
-// File. However, then we would be forced to #include hashmap in file.h
-// which seems to be a high price just for a simple beautification...
-static StringIntMap *_defaultDirectories;
-static StringMap *_filesMap;
-
-static FILE *fopenNoCase(const String &filename, const String &directory, const char *mode) {
- FILE *file;
- String buf(directory);
- uint i;
-
-#if !defined(__GP32__) && !defined(PALMOS_MODE)
- // Add a trailing slash, if necessary.
- if (!buf.empty()) {
- const char c = buf.lastChar();
- if (c != ':' && c != '/' && c != '\\')
- buf += '/';
- }
-#endif
-
- // Append the filename to the path string
- const int offsetToFileName = buf.size();
- buf += filename;
-
- //
- // Try to open the file normally
- //
- file = fopen(buf.c_str(), mode);
-
- //
- // Try again, with file name converted to upper case
- //
- if (!file) {
- for (i = offsetToFileName; i < buf.size(); ++i) {
- buf[i] = toupper(buf[i]);
- }
- file = fopen(buf.c_str(), mode);
- }
-
- //
- // Try again, with file name converted to lower case
- //
- if (!file) {
- for (i = offsetToFileName; i < buf.size(); ++i) {
- buf[i] = tolower(buf[i]);
- }
- file = fopen(buf.c_str(), mode);
- }
-
- //
- // Try again, with file name capitalized
- //
- if (!file) {
- i = offsetToFileName;
- buf[i] = toupper(buf[i]);
- file = fopen(buf.c_str(), mode);
- }
-
-#ifdef __amigaos4__
- //
- // Work around for possibility that someone uses AmigaOS "newlib" build with SmartFileSystem (blocksize 512 bytes), leading
- // to buffer size being only 512 bytes. "Clib2" sets the buffer size to 8KB, resulting smooth movie playback. This forces the buffer
- // to be enough also when using "newlib" compile on SFS.
- //
- if (file) {
- setvbuf(file, NULL, _IOFBF, 8192);
- }
-#endif
-
- return file;
-}
-
-void File::addDefaultDirectory(const String &directory) {
- FilesystemNode dir(directory);
- addDefaultDirectoryRecursive(dir, 1);
-}
-
-void File::addDefaultDirectoryRecursive(const String &directory, int level, const String &prefix) {
- FilesystemNode dir(directory);
- addDefaultDirectoryRecursive(dir, level, prefix);
-}
-/*
-void File::addDefaultDirectory(const FilesystemNode &directory) {
- addDefaultDirectoryRecursive(directory, 1);
-}
-
-void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, const String &prefix) {
- if (level <= 0)
- return;
-
- FSList fslist;
- if (!dir.listDir(fslist, FilesystemNode::kListAll)) {
- // Failed listing the contents of this node, so it is either not a
- // directory, or just doesn't exist at all.
- return;
- }
-
- if (!_defaultDirectories)
- _defaultDirectories = new StringIntMap;
-
- // Do not add directories multiple times, unless this time they are added
- // with a bigger depth.
- const String &directory(dir.path());
- if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level)
- return;
- (*_defaultDirectories)[directory] = level;
-
- if (!_filesMap)
- _filesMap = new StringMap;
-
- for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
- if (file->isDirectory()) {
- addDefaultDirectoryRecursive(file->path(), level - 1, prefix + file->name() + "/");
- } else {
- String lfn(prefix);
- lfn += file->name();
- lfn.toLowercase();
- if (!_filesMap->contains(lfn)) {
- (*_filesMap)[lfn] = file->path();
- }
- }
- }
-}
-*/
-void File::resetDefaultDirectories() {
- delete _defaultDirectories;
- delete _filesMap;
-
- _defaultDirectories = 0;
- _filesMap = 0;
-}
-
-File::File()
- : _handle(0), _ioFailed(false) {
-}
-
-//#define DEBUG_FILE_REFCOUNT
-
-File::~File() {
-#ifdef DEBUG_FILE_REFCOUNT
- warning("File::~File on file '%s'", _name.c_str());
-#endif
- close();
-}
-
-
-bool File::open(const String &filename, AccessMode mode) {
- assert(mode == kFileReadMode || mode == kFileWriteMode);
-
- if (filename.empty()) {
- error("File::open: No filename was specified");
- }
-
- if (_handle) {
- error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
- }
-
- _name.clear();
- clearIOFailed();
-
- String fname(filename);
- fname.toLowercase();
-
- const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
- if (mode == kFileWriteMode) {
- _handle = fopenNoCase(filename, "", modeStr);
- } else if (_filesMap && _filesMap->contains(fname)) {
- fname = (*_filesMap)[fname];
- debug(3, "Opening hashed: %s", fname.c_str());
- _handle = fopen(fname.c_str(), modeStr);
- } else if (_filesMap && _filesMap->contains(fname + ".")) {
- // WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
- // sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
- fname = (*_filesMap)[fname + "."];
- debug(3, "Opening hashed: %s", fname.c_str());
- _handle = fopen(fname.c_str(), modeStr);
- } else {
-
- if (_defaultDirectories) {
- // Try all default directories
- StringIntMap::const_iterator x(_defaultDirectories->begin());
- for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
- _handle = fopenNoCase(filename, x->_key, modeStr);
- }
- }
-
- // Last resort: try the current directory
- if (_handle == NULL)
- _handle = fopenNoCase(filename, "", modeStr);
-
- // Last last (really) resort: try looking inside the application bundle on Mac OS X for the lowercase file.
-#ifdef MACOSX
- if (!_handle) {
- CFStringRef cfFileName = CFStringCreateWithBytes(NULL, (const UInt8 *)filename.c_str(), filename.size(), kCFStringEncodingASCII, false);
- CFURLRef fileUrl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfFileName, NULL, NULL);
- if (fileUrl) {
- UInt8 buf[256];
- if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) {
- _handle = fopen((char *)buf, modeStr);
- }
- CFRelease(fileUrl);
- }
- CFRelease(cfFileName);
- }
-#endif
-
- }
-
- if (_handle == NULL) {
- if (mode == kFileReadMode)
- debug(2, "File %s not found", filename.c_str());
- else
- debug(2, "File %s not opened", filename.c_str());
- return false;
- }
-
-
- _name = filename;
-
-#ifdef DEBUG_FILE_REFCOUNT
- warning("File::open on file '%s'", _name.c_str());
-#endif
-
- return true;
-}
-/*
-bool File::open(const FilesystemNode &node, AccessMode mode) {
- assert(mode == kFileReadMode || mode == kFileWriteMode);
-
- if (!node.isValid()) {
- warning("File::open: Trying to open an invalid FilesystemNode object");
- return false;
- } else if (node.isDirectory()) {
- warning("File::open: Trying to open a FilesystemNode which is a directory");
- return false;
- }
-
- String filename(node.name());
-
- if (_handle) {
- error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
- }
-
- clearIOFailed();
- _name.clear();
-
- const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
-
- _handle = fopen(node.path().c_str(), modeStr);
-
- if (_handle == NULL) {
- if (mode == kFileReadMode)
- debug(2, "File %s not found", filename.c_str());
- else
- debug(2, "File %s not opened", filename.c_str());
- return false;
- }
-
- _name = filename;
-
-#ifdef DEBUG_FILE_REFCOUNT
- warning("File::open on file '%s'", _name.c_str());
-#endif
-
- return true;
-}
-
-bool File::exists(const String &filename) {
- // First try to find the file it via a FilesystemNode (in case an absolute
- // path was passed). But we only use this to filter out directories.
- FilesystemNode file(filename);
- // FIXME: can't use isValid() here since at the time of writing
- // FilesystemNode is to be unable to find for example files
- // added in extrapath
- if (file.isDirectory())
- return false;
-
- // Next, try to locate the file by *opening* it in read mode. This has
- // multiple effects:
- // 1) It takes _filesMap and _defaultDirectories into consideration -> good
- // 2) It returns true if and only if File::open is possible on the file -> good
- // 3) If this method is misused, it could lead to an fopen call on a directory
- // -> bad!
- // 4) It also checks whether we can read the file. This is not 100%
- // desirable; after all, even when we can't read it, the file is present.
- // Since this method is often used to check whether a file should be
- // re-created, that's not nice.
- //
- // TODO/FIXME: We should clarify the semantics of this method, and then
- // maybe should introduce several new methods:
- // fileExistsAndReadable
- // fileExists
- // fileExistsAtPath
- // dirExists
- // dirExistsAtPath
- // or maybe only 1-2 methods which take some params :-).
-
- File tmp;
- return tmp.open(filename, kFileReadMode);
-}
-
-void File::close() {
- if (_handle)
- fclose((FILE *)_handle);
- _handle = NULL;
-}
-*/
-bool File::isOpen() const {
- return _handle != NULL;
-}
-
-bool File::ioFailed() const {
- return _ioFailed != 0;
-}
-
-void File::clearIOFailed() {
- _ioFailed = false;
-}
-
-bool File::eof() const {
- if (_handle == NULL) {
- error("File::eof: File is not open!");
- return false;
- }
-
- return feof((FILE *)_handle) != 0;
-}
-
-uint32 File::pos() const {
- if (_handle == NULL) {
- error("File::pos: File is not open!");
- return 0;
- }
-
- return ftell((FILE *)_handle);
-}
-
-uint32 File::size() const {
- if (_handle == NULL) {
- error("File::size: File is not open!");
- return 0;
- }
-
- uint32 oldPos = ftell((FILE *)_handle);
- fseek((FILE *)_handle, 0, SEEK_END);
- uint32 length = ftell((FILE *)_handle);
- fseek((FILE *)_handle, oldPos, SEEK_SET);
-
- return length;
-}
-
-void File::seek(int32 offs, int whence) {
- if (_handle == NULL) {
- error("File::seek: File is not open!");
- return;
- }
-
- if (fseek((FILE *)_handle, offs, whence) != 0)
- clearerr((FILE *)_handle);
-}
-
-uint32 File::read(void *ptr, uint32 len) {
- byte *ptr2 = (byte *)ptr;
- uint32 real_len;
-
- if (_handle == NULL) {
- error("File::read: File is not open!");
- return 0;
- }
-
- if (len == 0)
- return 0;
-
- real_len = fread(ptr2, 1, len, (FILE *)_handle);
- if (real_len < len) {
- _ioFailed = true;
- }
-
- return real_len;
-}
-
-uint32 File::write(const void *ptr, uint32 len) {
- if (_handle == NULL) {
- error("File::write: File is not open!");
- return 0;
- }
-
- if (len == 0)
- return 0;
-
- if ((uint32)fwrite(ptr, 1, len, (FILE *)_handle) != len) {
- _ioFailed = true;
- }
-
- return len;
-}
-
-} // End of namespace Common
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/file.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,120 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/file.h $
- * $Id: file.h 26017 2007-03-08 16:46:02Z fingolfin $
- *
- */
-
-#ifndef COMMON_FILE_H
-#define COMMON_FILE_H
-
-#include "common/stdafx.h"
-#include "common/scummsys.h"
-#include "common/str.h"
-#include "common/stream.h"
-
-class FilesystemNode;
-
-namespace Common {
-
-class File : public SeekableReadStream, public WriteStream {
-protected:
- /** File handle to the actual file; 0 if no file is open. */
- void *_handle;
-
- /** Status flag which tells about recent I/O failures. */
- bool _ioFailed;
-
- /** The name of this file, for debugging. */
- String _name;
-
-private:
- // Disallow copying File objects. There is not strict reason for this,
- // except that so far we never had real need for such a feature, and
- // code that accidentally copied File objects tended to break in strange
- // ways.
- File(const File &f);
- File &operator =(const File &f);
-
-public:
- enum AccessMode {
- kFileReadMode = 1,
- kFileWriteMode = 2
- };
-
- static void addDefaultDirectory(const String &directory);
- static void addDefaultDirectoryRecursive(const String &directory, int level = 4, const String &prefix = "");
-
- /*static void addDefaultDirectory(const FilesystemNode &directory);
- static void addDefaultDirectoryRecursive(const FilesystemNode &directory, int level = 4, const String &prefix = "");*/
-
- static void resetDefaultDirectories();
-
- File();
- virtual ~File();
-
- /**
- * Checks if a given file exists in any of the current default paths
- * (those were/are added by addDefaultDirectory and/or
- * addDefaultDirectoryRecursive).
- *
- * @param filename: the file to check for
- * @return: true if the file exists, else false
- */
- //static bool exists(const String &filename);
-
- virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
- //virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
-
- virtual void close();
-
- /**
- * Checks if the object opened a file successfully.
- *
- * @return: true if any file is opened, false otherwise.
- */
- bool isOpen() const;
-
- /**
- * Returns the filename of the opened file.
- *
- * @return: the filename
- */
- const char *name() const { return _name.c_str(); }
-
- bool ioFailed() const;
- void clearIOFailed();
- bool eos() const { return eof(); }
-
- /**
- * Checks for end of file.
- *
- * @return: true if the end of file is reached, false otherwise.
- */
- bool eof() const;
-
- uint32 pos() const;
- uint32 size() const;
- void seek(int32 offs, int whence = SEEK_SET);
- uint32 read(void *dataPtr, uint32 dataSize);
- uint32 write(const void *dataPtr, uint32 dataSize);
-};
-
-} // End of namespace Common
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/fs.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/fs.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/fs.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,194 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/fs.h $
- * $Id: fs.h 26015 2007-03-08 15:02:13Z fingolfin $
- */
-
-#ifndef COMMON_FS_H
-#define COMMON_FS_H
-
-#include "common/array.h"
-#include "common/str.h"
-
-//namespace Common {
-
-class FilesystemNode;
-class AbstractFilesystemNode;
-
-
-/**
- * List of multiple file system nodes. E.g. the contents of a given directory.
- * This is subclass instead of just a typedef so that we can use forward
- * declarations of it in other places.
- */
-class FSList : public Common::Array<FilesystemNode> {};
-
-
-/**
- * FilesystemNode provides an abstraction for file pathes, allowing for portable
- * file system browsing. To this ends, multiple or single roots have to be supported
- * (compare Unix with a single root, Windows with multiple roots C:, D:, ...).
- *
- * To this end, we abstract away from paths; implementations can be based on
- * paths (and it's left to them whether / or \ or : is the path separator :-);
- * but it is also possible to use inodes or vrefs (MacOS 9) or anything else.
- *
- * NOTE: Backends still have to provide a way to extract a path from a FSIntern
- *
- * You may ask now: "isn't this cheating? Why do we go through all this when we use
- * a path in the end anyway?!?".
- * Well, for once as long as we don't provide our own file open/read/write API, we
- * still have to use fopen(). Since all our targets already support fopen(), it should
- * be possible to get a fopen() compatible string for any file system node.
- *
- * Secondly, with this abstraction layer, we still avoid a lot of complications based on
- * differences in FS roots, different path separators, or even systems with no real
- * paths (MacOS 9 doesn't even have the notion of a "current directory").
- * And if we ever want to support devices with no FS in the classical sense (Palm...),
- * we can build upon this.
- */
-class FilesystemNode {
-private:
- AbstractFilesystemNode *_realNode;
- int *_refCount;
-
- FilesystemNode(AbstractFilesystemNode *realNode);
-
-public:
- /**
- * Flag to tell listDir() which kind of files to list.
- */
- enum ListMode {
- kListFilesOnly = 1,
- kListDirectoriesOnly = 2,
- kListAll = 3
- };
-
- /**
- * Create a new invalid FilesystemNode. In other words, isValid() for that
- * node returns false, and if you try to get it's path, an assert is
- * triggered.
- */
- FilesystemNode();
-
- /**
- * Create a new FilesystemNode referring to the specified path. This is
- * the counterpart to the path() method.
- *
- * If path is empty or equals ".", then a node representing the "current
- * directory" will be created. If that is not possible (since e.g. the
- * operating system doesn't support the concept), some other directory is
- * used (usually the root directory).
- */
- FilesystemNode(const Common::String &path);
-
- /**
- * Copy constructor.
- */
- FilesystemNode(const FilesystemNode &node);
-
- /**
- * Destructor.
- */
- virtual ~FilesystemNode();
-
- /**
- * Copy operator.
- */
- FilesystemNode &operator =(const FilesystemNode &node);
-
- /**
- * Checks if the FilesystemNode is valid for any usage
- */
- bool isValid() const;
-
- /**
- * Get the parent node of this node. If this node has no parent node,
- * then it returns a duplicate of this node.
- */
- FilesystemNode getParent() const;
-
- /**
- * Fetch a child node of this node, with the given name. Only valid for
- * directory nodes (an assertion is triggered otherwise). If no no child
- * node with the given name exists, an invalid node is returned.
- */
- FilesystemNode getChild(const Common::String &name) const;
-
- /**
- * Return a list of child nodes of this directory node. If called on a node
- * that does not represent a directory, false is returned.
- * @return true if succesful, false otherwise (e.g. when the directory does not exist).
- * @todo Rename this to listChildren or getChildren.
- */
- virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const;
-
- /**
- * Is this node pointing to a directory?
- * @todo Currently we assume that a valid node that is not a directory
- * automatically is a file (ignoring things like symlinks). That might
- * actually be OK... but we could still add an isFile method. Or even replace
- * isValid and isDirectory by a getType() method that can return values like
- * kDirNodeType, kFileNodeType, kInvalidNodeType.
- */
- virtual bool isDirectory() const;
-
- /**
- * Return a human readable string for this node, usable for display (e.g.
- * in the GUI code). Do *not* rely on it being usable for anything else,
- * like constructing paths!
- * @return the display name
- */
- virtual Common::String displayName() const;
-
- /**
- * Return a string representation of the name of the file. This is can be
- * used e.g. by detection code that relies on matching the name of a given
- * file. But it is *not* suitable for use with fopen / File::open, nor
- * should it be archived.
- *
- * @return the file name
- */
- virtual Common::String name() const;
-
- /**
- * Return a string representation of the file which can be passed to fopen(),
- * and is suitable for archiving (i.e. writing to the config file).
- * This will usually be a 'path' (hence the name of the method), but can
- * be anything that fulfills the above criterions.
- *
- * @note Do not assume that this string contains (back)slashes or any
- * other kind of 'path separators'.
- *
- * @return the 'path' represented by this filesystem node
- */
- virtual Common::String path() const;
-
- /**
- * Compare the name of this node to the name of another. Directories
- * go before normal files.
- */
- bool operator< (const FilesystemNode& node) const;
-
-protected:
- void decRefCount();
-};
-
-//} // End of namespace Common
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/func.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/func.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/func.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,90 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/func.h $
- * $Id: func.h 21939 2006-04-16 13:01:41Z fingolfin $
- */
-
-#ifndef COMMON_FUNC_H
-#define COMMON_FUNC_H
-
-#include "common/scummsys.h"
-
-namespace Common {
-
-template <class T>
-struct EqualTo {
- bool operator()(const T& x, const T& y) const { return x == y; }
-};
-
-template <class T>
-struct Less {
- bool operator()(const T& x, const T& y) const { return x < y; }
-};
-
-/**
- * Base template for hash functor objects, used by HashMap.
- * This needs to be specialized for every type that you need to hash.
- */
-template <typename T> struct Hash;
-
-
-#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \
- template <> struct Hash<T> { \
- uint operator()(T val) const { return (uint)val; } \
- }
-
-GENERATE_TRIVIAL_HASH_FUNCTOR(bool);
-GENERATE_TRIVIAL_HASH_FUNCTOR(char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(signed char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned char);
-GENERATE_TRIVIAL_HASH_FUNCTOR(short);
-GENERATE_TRIVIAL_HASH_FUNCTOR(int);
-GENERATE_TRIVIAL_HASH_FUNCTOR(long);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned short);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned int);
-GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
-
-#undef GENERATE_TRIVIAL_HASH_FUNCTOR
-
-
-// Simple sort function, modelled after std::sort.
-// Use it like this: sort(container.begin(), container.end()).
-// Also work on plain old int arrays etc.
-template <typename T>
-void sort(T first, T last) {
- if (first == last)
- return;
-
- // Simple selection sort
- T i(first);
- for (; i != last; ++i) {
- T minElem(i);
- T j(i);
- ++j;
- for (; j != last; ++j)
- if (*j < *minElem)
- minElem = j;
- if (minElem != i)
- SWAP(*minElem, *i);
- }
-}
-
-
-} // End of namespace Common
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hash-str.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hash-str.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hash-str.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,79 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/hash-str.h $
- * $Id: hash-str.h 23634 2006-07-30 12:21:54Z fingolfin $
- */
-
-#ifndef COMMON_HASH_STR_H
-#define COMMON_HASH_STR_H
-
-#include "common/hashmap.h"
-#include "common/str.h"
-
-namespace Common {
-
-uint hashit(const char *str);
-uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string
-
-
-// FIXME: The following functors obviously are not consistently named
-
-struct CaseSensitiveString_EqualTo {
- bool operator()(const String& x, const String& y) const { return strcmp(x.c_str(), y.c_str()) == 0; }
-};
-
-struct CaseSensitiveString_Hash {
- uint operator()(const String& x) const { return hashit(x.c_str()); }
-};
-
-
-struct IgnoreCase_EqualTo {
- bool operator()(const String& x, const String& y) const { return scumm_stricmp(x.c_str(), y.c_str()) == 0; }
-};
-
-struct IgnoreCase_Hash {
- uint operator()(const String& x) const { return hashit_lower(x.c_str()); }
-};
-
-
-
-typedef HashMap<String, String, IgnoreCase_Hash, IgnoreCase_EqualTo> StringMap;
-
-
-#if 0
-// Specalization of the Hash functor for String objects.
-template <>
-struct Hash<String> {
- uint operator()(const String& s) const {
- return hashit(s.c_str());
- }
-};
-
-template <>
-struct Hash<const char *> {
- uint operator()(const char *s) const {
- return hashit(s);
- }
-};
-#endif
-
-
-} // End of namespace Common
-
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,90 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/hashmap.cpp $
- * $Id: hashmap.cpp 26044 2007-03-09 23:46:45Z fingolfin $
- *
- */
-
-// The hash map (associative array) implementation in this file is
-// based on code by Andrew Y. Ng, 1996:
-
-/*
- * Copyright (c) 1998-2003 Massachusetts Institute of Technology.
- * This code was developed as part of the Haystack research project
- * (http://haystack.lcs.mit.edu/). Permission is hereby granted,
- * free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit
- * persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "common/hashmap.h"
-
-namespace Common {
-
-// const char *:
-uint hashit(const char *p) {
- uint hash = 0;
- byte c;
- while ((c = *p++))
- hash = (hash * 31 + c);
- return hash;
-}
-
-uint hashit_lower(const char *p) {
- uint hash = 0;
- byte c;
- while ((c = *p++))
- hash = (hash * 31 + tolower(c));
- return hash;
-}
-
-// The following table is taken from the GNU ISO C++ Library's hashtable.h file.
-static const uint primes[] = {
- 53ul, 97ul, 193ul, 389ul, 769ul,
- 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
- 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
- 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
- 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
- 1610612741ul, 3221225473ul, 4294967291ul
-};
-
-uint nextTableSize(uint x) {
- int i = 0;
- while (x >= primes[i])
- i++;
- return primes[i];
-}
-
-
-} // End of namespace Common
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/hashmap.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,458 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/hashmap.h $
- * $Id: hashmap.h 26115 2007-03-12 22:34:29Z fingolfin $
- *
- */
-
-// The hash map (associative array) implementation in this file is
-// based on code by Andrew Y. Ng, 1996:
-
-/*
- * Copyright (c) 1998-2003 Massachusetts Institute of Technology.
- * This code was developed as part of the Haystack research project
- * (http://haystack.lcs.mit.edu/). Permission is hereby granted,
- * free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit
- * persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef COMMON_HASHMAP_H
-#define COMMON_HASHMAP_H
-
-#include "common/stdafx.h"
-#include "common/func.h"
-#include "common/str.h"
-#include "common/util.h"
-
-namespace Common {
-
-// The table sizes ideally are primes. We use a helper function to find
-// suitable table sizes.
-uint nextTableSize(uint x);
-
-
-// Enable the following #define if you want to check how many collisions the
-// code produces (many collisions indicate either a bad hash function, or a
-// hash table that is too small).
-//#define DEBUG_HASH_COLLISIONS
-
-/**
- * HashMap<Key,Val> maps objects of type Key to objects of type Val.
- * For each used Key type, we need an "uint hashit(Key,uint)" function
- * that computes a hash for the given Key object and returns it as an
- * an integer from 0 to hashsize-1, and also an "equality functor".
- * that returns true if if its two arguments are to be considered
- * equal. Also, we assume that "=" works on Val objects for assignment.
- *
- * If aa is an HashMap<Key,Val>, then space is allocated each time aa[key] is
- * referenced, for a new key. If the object is const, then an assertion is
- * triggered instead. Hence if you are not sure whether a key is contained in
- * the map, use contains() first to check for its presence.
- */
-template <class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> >
-class HashMap {
- friend class const_iterator;
-private:
-#if defined (PALMOS_MODE)
-public:
-#endif
-
- typedef HashMap<Key, Val, HashFunc, EqualFunc> HM_t;
-
- struct Node {
- const Key _key;
- Val _value;
- Node(const Key &key) : _key(key) {}
- };
-
- Node **_arr; // hashtable of size arrsize.
- uint _arrsize, _nele;
-
- HashFunc _hash;
- EqualFunc _equal;
-
- // Default value, returned by the const getVal.
- const Val _defaultVal;
-
-#ifdef DEBUG_HASH_COLLISIONS
- mutable int _collisions, _lookups;
-#endif
-
- void assign(const HM_t& map);
- int lookup(const Key &key) const;
- int lookupAndCreateIfMissing(const Key &key);
- void expand_array(uint newsize);
-
-public:
- class const_iterator {
- typedef const HashMap<Key, Val, HashFunc, EqualFunc> * hashmap_t;
- friend class HashMap<Key, Val, HashFunc, EqualFunc>;
- protected:
- uint _idx;
- hashmap_t _hashmap;
- const_iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {}
-
- const Node *deref() const {
- assert(_hashmap != 0);
- Node *node = _hashmap->_arr[_idx];
- assert(node != 0);
- return node;
- }
-
- public:
- const_iterator() : _idx(0), _hashmap(0) {}
-
- const Node &operator *() const { return *deref(); }
- const Node *operator->() const { return deref(); }
- bool operator ==(const const_iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
- bool operator !=(const const_iterator &iter) const { return !(*this == iter); }
- const_iterator operator ++() {
- assert(_hashmap);
- do {
- _idx++;
- } while (_idx < _hashmap->_arrsize && _hashmap->_arr[_idx] == 0);
- if (_idx >= _hashmap->_arrsize)
- _idx = (uint)-1;
-
- return *this;
- }
- };
-
- HashMap();
- HashMap(const HM_t& map);
- ~HashMap();
-
- HM_t &operator =(const HM_t &map) {
- if (this == &map)
- return *this;
-
- // Remove the previous content and ...
- clear();
- delete[] _arr;
- // ... copy the new stuff.
- assign(map);
- return *this;
- }
-
- bool contains(const Key &key) const;
-
- Val &operator [](const Key &key);
- const Val &operator [](const Key &key) const;
-
- Val &getVal(const Key &key);
- const Val &getVal(const Key &key) const;
- void setVal(const Key &key, const Val &val);
-
- void clear(bool shrinkArray = 0);
-
- void erase(const Key &key);
-
- uint size() const { return _nele; }
-
- const_iterator begin() const {
- // Find and return the first non-empty entry
- for (uint ctr = 0; ctr < _arrsize; ++ctr) {
- if (_arr[ctr])
- return const_iterator(ctr, this);
- }
- return end();
- }
- const_iterator end() const {
- return const_iterator((uint)-1, this);
- }
-
- const_iterator find(const Key &key) const {
- uint ctr = lookup(key);
- if (_arr[ctr])
- return const_iterator(ctr, this);
- return end();
- }
-
- // TODO: insert() method?
-
- bool empty() const {
- return (_nele == 0);
- }
-};
-
-//-------------------------------------------------------
-// HashMap functions
-
-/**
- * Base constructor, creates an empty hashmap.
- */
-template <class Key, class Val, class HashFunc, class EqualFunc>
-HashMap<Key, Val, HashFunc, EqualFunc>::HashMap()
- : _defaultVal() {
- _arrsize = nextTableSize(0);
- _arr = new Node *[_arrsize];
- assert(_arr != NULL);
- memset(_arr, 0, _arrsize * sizeof(Node *));
-
- _nele = 0;
-
-#ifdef DEBUG_HASH_COLLISIONS
- _collisions = 0;
- _lookups = 0;
-#endif
-}
-
-/**
- * Copy constructor, creates a full copy of the given hashmap.
- * We must provide a custom copy constructor as we use pointers
- * to heap buffers for the internal storage.
- */
-template <class Key, class Val, class HashFunc, class EqualFunc>
-HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t& map)
- : _defaultVal() {
- assign(map);
-}
-
-/**
- * Destructor, frees all used memory.
- */
-template <class Key, class Val, class HashFunc, class EqualFunc>
-HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
- for (uint ctr = 0; ctr < _arrsize; ++ctr)
- if (_arr[ctr] != NULL)
- delete _arr[ctr];
-
- delete[] _arr;
-}
-
-/**
- * Internal method for assigning the content of another HashMap
- * to this one.
- *
- * @note We do *not* deallocate the previous storage here -- the caller is
- * responsible for doing that!
- */
-template <class Key, class Val, class HashFunc, class EqualFunc>
-void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t& map) {
- _arrsize = map._arrsize;
- _arr = new Node *[_arrsize];
- assert(_arr != NULL);
- memset(_arr, 0, _arrsize * sizeof(Node *));
-
- // Simply clone the map given to us, one by one.
- _nele = 0;
- for (uint ctr = 0; ctr < _arrsize; ++ctr) {
- if (map._arr[ctr] != NULL) {
- _arr[ctr] = new Node(*map._arr[ctr]);
- _nele++;
- }
- }
- // Perform a sanity check (to help track down hashmap corruption)
- assert(_nele == map._nele);
-}
-
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
- for (uint ctr = 0; ctr < _arrsize; ++ctr) {
- if (_arr[ctr] != NULL) {
- delete _arr[ctr];
- _arr[ctr] = NULL;
- }
- }
-
- if (shrinkArray && _arrsize > nextTableSize(0)) {
- delete[] _arr;
-
- _arrsize = nextTableSize(0);
- _arr = new Node *[_arrsize];
- assert(_arr != NULL);
- memset(_arr, 0, _arrsize * sizeof(Node *));
- }
-
- _nele = 0;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-void HashMap<Key, Val, HashFunc, EqualFunc>::expand_array(uint newsize) {
- assert(newsize > _arrsize);
- uint ctr, dex;
-
- const uint old_nele = _nele;
- const uint old_arrsize = _arrsize;
- Node **old_arr = _arr;
-
- // allocate a new array
- _nele = 0;
- _arrsize = newsize;
- _arr = new Node *[_arrsize];
- assert(_arr != NULL);
- memset(_arr, 0, _arrsize * sizeof(Node *));
-
- // rehash all the old elements
- for (ctr = 0; ctr < old_arrsize; ++ctr) {
- if (old_arr[ctr] == NULL)
- continue;
-
- // Insert the element from the old table into the new table.
- // Since we know that no key exists twice in the old table, we
- // can do this slightly better than by calling lookup, since we
- // don't have to call _equal().
- dex = _hash(old_arr[ctr]->_key) % _arrsize;
- while (_arr[dex] != NULL) {
- dex = (dex + 1) % _arrsize;
- }
-
- _arr[dex] = old_arr[ctr];
- _nele++;
- }
-
- // Perform a sanity check: Old number of elements should match the new one!
- // This check will fail if some previous operation corrupted this hashmap.
- assert(_nele == old_nele);
-
- delete[] old_arr;
-
- return;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
- uint ctr = _hash(key) % _arrsize;
-
- while (_arr[ctr] != NULL && !_equal(_arr[ctr]->_key, key)) {
- ctr = (ctr + 1) % _arrsize;
-
-#ifdef DEBUG_HASH_COLLISIONS
- _collisions++;
-#endif
- }
-
-#ifdef DEBUG_HASH_COLLISIONS
- _lookups++;
- fprintf(stderr, "collisions %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d\n",
- _collisions, _lookups, ((double) _collisions / (double)_lookups),
- (const void *)this, _arrsize, _nele);
-#endif
-
- return ctr;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-int HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) {
- uint ctr = lookup(key);
-
- if (_arr[ctr] == NULL) {
- _arr[ctr] = new Node(key);
- _nele++;
-
- // Keep the load factor below 75%.
- if (_nele > _arrsize * 75 / 100) {
- expand_array(nextTableSize(_arrsize));
- ctr = lookup(key);
- }
- }
-
- return ctr;
-}
-
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const {
- uint ctr = lookup(key);
- return (_arr[ctr] != NULL);
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator [](const Key &key) {
- return getVal(key);
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator [](const Key &key) const {
- return getVal(key);
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
- uint ctr = lookupAndCreateIfMissing(key);
- assert(_arr[ctr] != NULL);
- return _arr[ctr]->_value;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const {
- uint ctr = lookup(key);
- if (_arr[ctr] != NULL)
- return _arr[ctr]->_value;
- else
- return _defaultVal;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) {
- uint ctr = lookupAndCreateIfMissing(key);
- assert(_arr[ctr] != NULL);
- _arr[ctr]->_value = val;
-}
-
-template <class Key, class Val, class HashFunc, class EqualFunc>
-void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) {
- // This is based on code in the Wikipedia article on Hash tables.
- uint i = lookup(key);
- if (_arr[i] == NULL)
- return; // key wasn't present, so no work has to be done
- // If we remove a key, we must check all subsequent keys and possibly
- // reinsert them.
- uint j = i;
- delete _arr[i];
- _arr[i] = NULL;
- while (true) {
- // Look at the next table slot
- j = (j + 1) % _arrsize;
- // If the next slot is empty, we are done
- if (_arr[j] == NULL)
- break;
- // Compute the slot where the content of the next slot should normally be,
- // assuming an empty table, and check whether we have to move it.
- uint k = _hash(_arr[j]->_key) % _arrsize;
- if ((j > i && (k <= i || k > j)) ||
- (j < i && (k <= i && k > j)) ) {
- _arr[i] = _arr[j];
- i = j;
- }
- }
- _arr[i] = NULL;
- return;
-}
-
-} // End of namespace Common
-
-#endif
Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/scummsys.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/scummsys.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/scummsys.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -181,7 +181,11 @@
#else
/* need this for the SDL_BYTEORDER define */
- #include <SDL_byteorder.h>
+
+ #define SCUMM_LITTLE_ENDIAN
+
+ /* ZZZ
+ #include <SDL_byteorder.h>
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SCUMM_LITTLE_ENDIAN
@@ -189,8 +193,9 @@
#define SCUMM_BIG_ENDIAN
#else
#error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
+ #endif*/
+
#endif
- #endif
#endif
// You need to set this manually if necessary
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.cpp 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.cpp 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,449 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/str.cpp $
- * $Id: str.cpp 26044 2007-03-09 23:46:45Z fingolfin $
- */
-
-#include "common/stdafx.h"
-
-#include "common/str.h"
-#include "common/hash-str.h"
-#include "common/util.h"
-
-namespace Common {
-
-#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
-const String String::emptyString;
-#else
-const char *String::emptyString = "";
-#endif
-
-static int computeCapacity(int len) {
- // By default, for the capacity we use the nearest multiple of 32
- // that leaves at least 16 chars of extra space (in case the string
- // grows a bit).
- // Finally, we subtract 1 to compensate for the trailing zero byte.
- len += 16;
- return ((len + 32 - 1) & ~0x1F) - 1;
-}
-
-String::String(const char *str, uint32 len)
-: _len(0), _str(_storage) {
-
- // Init _storage member explicitly (ie. without calling its constructor)
- // for GCC 2.95.x compatibility (see also tracker item #1602879).
- _storage[0] = 0;
-
- if (str && *str) {
- const uint32 tmp = strlen(str);
- assert(len <= tmp);
- if (len <= 0)
- len = tmp;
- _len = len;
-
- if (len >= _builtinCapacity) {
- // Not enough internal storage, so allocate more
- _extern._capacity = computeCapacity(len);
- _extern._refCount = 0;
- _str = (char *)malloc(_extern._capacity+1);
- assert(_str != 0);
- }
-
- // Copy the string into the storage area
- memcpy(_str, str, len);
- _str[len] = 0;
- }
-}
-
-String::String(const String &str)
- : _len(str._len), _str(str.isStorageIntern() ? _storage : str._str) {
- if (str.isStorageIntern()) {
- // String in internal storage: just copy it
- memcpy(_storage, str._storage, _builtinCapacity);
- } else {
- // String in external storage: use refcount mechanism
- str.incRefCount();
- _extern._refCount = str._extern._refCount;
- _extern._capacity = str._extern._capacity;
- }
- assert(_str != 0);
-}
-
-String::~String() {
- decRefCount(_extern._refCount);
-}
-
-void String::incRefCount() const {
- assert(!isStorageIntern());
- if (_extern._refCount == 0) {
- _extern._refCount = new int(2);
- } else {
- ++(*_extern._refCount);
- }
-}
-
-void String::decRefCount(int *oldRefCount) {
- if (isStorageIntern())
- return;
-
- if (oldRefCount) {
- --(*oldRefCount);
- }
- if (!oldRefCount || *oldRefCount <= 0) {
- // The ref count reached zero, so we free the string storage
- // and the ref count storage.
- delete oldRefCount;
- free(_str);
-
- // Even though _str points to a freed memory block now,
- // we do not change its value, because any code that calls
- // decRefCount will have to do this afterwards anyway.
- }
-}
-
-String& String::operator =(const char *str) {
- uint32 len = strlen(str);
- ensureCapacity(len, false);
- _len = len;
- memcpy(_str, str, len + 1);
- return *this;
-}
-
-String &String::operator =(const String &str) {
- if (str.isStorageIntern()) {
- decRefCount(_extern._refCount);
- _len = str._len;
- _str = _storage;
- memcpy(_str, str._str, _len + 1);
- } else {
- str.incRefCount();
- decRefCount(_extern._refCount);
-
- _extern._refCount = str._extern._refCount;
- _extern._capacity = str._extern._capacity;
- _len = str._len;
- _str = str._str;
- }
-
- return *this;
-}
-
-String& String::operator =(char c) {
- ensureCapacity(1, false);
- _len = 1;
- _str[0] = c;
- _str[1] = 0;
- return *this;
-}
-
-String &String::operator +=(const char *str) {
- int len = strlen(str);
- if (len > 0) {
- ensureCapacity(_len + len, true);
-
- memcpy(_str + _len, str, len + 1);
- _len += len;
- }
- return *this;
-}
-
-String &String::operator +=(const String &str) {
- int len = str._len;
- if (len > 0) {
- ensureCapacity(_len + len, true);
-
- memcpy(_str + _len, str._str, len + 1);
- _len += len;
- }
- return *this;
-}
-
-String &String::operator +=(char c) {
- ensureCapacity(_len + 1, true);
-
- _str[_len++] = c;
- _str[_len] = 0;
-
- return *this;
-}
-
-bool String::hasPrefix(const char *x) const {
- assert(x != 0);
- // Compare x with the start of _str.
- const char *y = c_str();
- while (*x && *x == *y) {
- ++x;
- ++y;
- }
- // It's a prefix, if and only if all letters in x are 'used up' before
- // _str ends.
- return *x == 0;
-}
-
-bool String::hasSuffix(const char *x) const {
- assert(x != 0);
- // Compare x with the end of _str.
- const uint32 x_len = strlen(x);
- if (x_len > _len)
- return false;
- const char *y = c_str() + _len - x_len;
- while (*x && *x == *y) {
- ++x;
- ++y;
- }
- // It's a suffix, if and only if all letters in x are 'used up' before
- // _str ends.
- return *x == 0;
-}
-
-void String::deleteLastChar() {
- deleteChar(_len - 1);
-}
-
-void String::deleteChar(uint32 p) {
- assert(p < _len);
-
- // Call ensureCapacity to make sure we actually *own* the storage
- // to which _str points to -- we wouldn't want to modify a storage
- // which other string objects are sharing, after all.
- ensureCapacity(_len, true);
- while (p++ < _len)
- _str[p-1] = _str[p];
- _len--;
-}
-
-void String::clear() {
- decRefCount(_extern._refCount);
-
- _len = 0;
- _str = _storage;
- _storage[0] = 0;
-}
-
-void String::insertChar(char c, uint32 p) {
- assert(p <= _len);
-
- ensureCapacity(_len + 1, true);
- _len++;
- for (uint32 i = _len; i > p; --i)
- _str[i] = _str[i-1];
- _str[p] = c;
-}
-
-void String::toLowercase() {
- ensureCapacity(_len, true);
- for (uint32 i = 0; i < _len; ++i)
- _str[i] = tolower(_str[i]);
-}
-
-void String::toUppercase() {
- ensureCapacity(_len, true);
- for (uint32 i = 0; i < _len; ++i)
- _str[i] = toupper(_str[i]);
-}
-
-/**
- * Ensure that enough storage is available to store at least new_len
- * characters plus a null byte. In addition, if we currently share
- * the storage with another string, unshare it, so that we can safely
- * write to the storage.
- */
-void String::ensureCapacity(uint32 new_len, bool keep_old) {
- bool isShared;
- uint32 curCapacity, newCapacity;
- char *newStorage;
- int *oldRefCount = _extern._refCount;
-
- if (isStorageIntern()) {
- isShared = false;
- curCapacity = _builtinCapacity - 1;
- } else {
- isShared = (oldRefCount && *oldRefCount > 1);
- curCapacity = _extern._capacity;
- }
-
- // Special case: If there is enough space, and we do not share
- // the storage, then there is nothing to do.
- if (!isShared && new_len <= curCapacity)
- return;
-
- if (isShared && new_len <= _builtinCapacity - 1) {
- // We share the storage, but there is enough internal storage: Use that.
- newStorage = _storage;
- newCapacity = _builtinCapacity - 1;
- } else {
- // We need to allocate storage on the heap!
-
- // Compute a suitable new capacity limit
- newCapacity = computeCapacity(new_len);
-
- // Allocate new storage
- newStorage = (char *)malloc(newCapacity+1);
- assert(newStorage);
- }
-
- // Copy old data if needed, elsewise reset the new storage.
- if (keep_old) {
- assert(_len <= newCapacity);
- memcpy(newStorage, _str, _len + 1);
- } else {
- _len = 0;
- newStorage[0] = 0;
- }
-
- // Release hold on the old storage ...
- decRefCount(oldRefCount);
-
- // ... in favor of the new storage
- _str = newStorage;
-
- if (!isStorageIntern()) {
- // Set the ref count & capacity if we use an external storage.
- // It is important to do this *after* copying any old content,
- // else we would override data that has not yet been copied!
- _extern._refCount = 0;
- _extern._capacity = newCapacity;
- }
-}
-
-uint String::hash() const {
- return hashit(c_str());
-}
-
-#pragma mark -
-
-bool String::operator ==(const String &x) const {
- return equals(x);
-}
-
-bool String::operator ==(const char *x) const {
- assert(x != 0);
- return equals(x);
-}
-
-bool String::operator !=(const String &x) const {
- return !equals(x);
-}
-
-bool String::operator !=(const char *x) const {
- assert(x != 0);
- return !equals(x);
-}
-
-bool String::operator < (const String &x) const {
- return compareTo(x) < 0;
-}
-
-bool String::operator <= (const String &x) const {
- return compareTo(x) <= 0;
-}
-
-bool String::operator > (const String &x) const {
- return compareTo(x) > 0;
-}
-
-bool String::operator >= (const String &x) const {
- return compareTo(x) >= 0;
-}
-
-#pragma mark -
-
-bool operator == (const char* y, const String &x) {
- return (x == y);
-}
-
-bool operator != (const char* y, const String &x) {
- return x != y;
-}
-
-#pragma mark -
-
-bool String::equals(const String &x) const {
- return (0 == compareTo(x));
-}
-
-bool String::equals(const char *x) const {
- assert(x != 0);
- return (0 == compareTo(x));
-}
-
-bool String::equalsIgnoreCase(const String &x) const {
- return (0 == compareToIgnoreCase(x));
-}
-
-bool String::equalsIgnoreCase(const char *x) const {
- assert(x != 0);
- return (0 == compareToIgnoreCase(x));
-}
-
-int String::compareTo(const String &x) const {
- return compareTo(x.c_str());
-}
-
-int String::compareTo(const char *x) const {
- assert(x != 0);
- return strcmp(c_str(), x);
-}
-
-int String::compareToIgnoreCase(const String &x) const {
- return compareToIgnoreCase(x.c_str());
-}
-
-int String::compareToIgnoreCase(const char *x) const {
- assert(x != 0);
- return scumm_stricmp(c_str(), x);
-}
-
-#pragma mark -
-
-String operator +(const String &x, const String &y) {
- String temp(x);
- temp += y;
- return temp;
-}
-
-String operator +(const char *x, const String &y) {
- String temp(x);
- temp += y;
- return temp;
-}
-
-String operator +(const String &x, const char *y) {
- String temp(x);
- temp += y;
- return temp;
-}
-
-char *ltrim(char *t) {
- while (isspace(*t))
- t++;
- return t;
-}
-
-char *rtrim(char *t) {
- int l = strlen(t) - 1;
- while (l >= 0 && isspace(t[l]))
- t[l--] = 0;
- return t;
-}
-
-char *trim(char *t) {
- return rtrim(ltrim(t));
-}
-
-} // End of namespace Common
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/str.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,214 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/str.h $
- * $Id: str.h 26044 2007-03-09 23:46:45Z fingolfin $
- */
-
-#ifndef COMMON_STRING_H
-#define COMMON_STRING_H
-
-#include "common/scummsys.h"
-#include "common/array.h"
-
-namespace Common {
-
-/**
- * Simple string class for ScummVM. Provides automatic storage managment,
- * and overloads several operators in a 'natural' fashion, mimicking
- * the std::string class. Even provides simple iterators.
- *
- * This class tries to avoid allocating lots of small blocks on the heap,
- * since that is inefficient on several platforms supported by ScummVM.
- * Instead, small strings are stored 'inside' the string object (i.e. on
- * the stack, for stack allocated objects), and only for strings exceeding
- * a certain length do we allocate a buffer on the heap.
- */
-class String {
-protected:
- /**
- * The size of the internal storage. Increasing this means less heap
- * allocations are needed, at the cost of more stack memory usage,
- * and of course lots of wasted memory. Empirically, 90% or more of
- * all String instances are less than 32 chars long. If a platform
- * is very short on stack space, it would be possible to lower this.
- * A value of 24 still seems acceptable, though considerably worse,
- * while 16 seems to be the lowest you want to go... Anything lower
- * than 8 makes no sense, since that's the size of member _extern
- * (on 32 bit machines; 12 bytes on systems with 64bit pointers).
- */
- static const uint32 _builtinCapacity = 32;
-
- /**
- * Length of the string. Stored to avoid having to call strlen
- * a lot. Yes, we limit ourselves to strings shorter than 4GB --
- * on purpose :-).
- */
- uint32 _len;
-
- /**
- * Pointer to the actual string storage. Either points to _storage,
- * or to a block allocated on the heap via malloc.
- */
- char *_str;
-
-
- union {
- /**
- * Internal string storage.
- */
- char _storage[_builtinCapacity];
- /**
- * External string storage data -- the refcounter, and the
- * capacity of the string _str points to.
- */
- struct {
- mutable int *_refCount;
- uint32 _capacity;
- } _extern;
- };
-
- inline bool isStorageIntern() const {
- return _str == _storage;
- }
-
-public:
-#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
- static const String emptyString;
-#else
- static const char *emptyString;
-#endif
-
- String() : _len(0), _str(_storage) { _storage[0] = 0; }
- String(const char *str, uint32 len = 0);
- String(const String &str);
- virtual ~String();
-
- String &operator =(const char *str);
- String &operator =(const String &str);
- String &operator =(char c);
- String &operator +=(const char *str);
- String &operator +=(const String &str);
- String &operator +=(char c);
-
- bool operator ==(const String &x) const;
- bool operator ==(const char *x) const;
- bool operator !=(const String &x) const;
- bool operator !=(const char *x) const;
-
- bool operator <(const String &x) const;
- bool operator <=(const String &x) const;
- bool operator >(const String &x) const;
- bool operator >=(const String &x) const;
-
- bool equals(const String &x) const;
- bool equalsIgnoreCase(const String &x) const;
- int compareTo(const String &x) const; // strcmp clone
- int compareToIgnoreCase(const String &x) const; // stricmp clone
-
- bool equals(const char *x) const;
- bool equalsIgnoreCase(const char *x) const;
- int compareTo(const char *x) const; // strcmp clone
- int compareToIgnoreCase(const char *x) const; // stricmp clone
-
-
-
- bool hasSuffix(const char *x) const;
- bool hasPrefix(const char *x) const;
-
- inline const char *c_str() const { return _str; }
- inline uint size() const { return _len; }
-
- inline bool empty() const { return (_len == 0); }
- char lastChar() const { return (_len > 0) ? _str[_len-1] : 0; }
-
- char operator [](int idx) const {
- assert(_str && idx >= 0 && idx < (int)_len);
- return _str[idx];
- }
-
- char &operator [](int idx) {
- assert(_str && idx >= 0 && idx < (int)_len);
- return _str[idx];
- }
-
- void deleteLastChar();
- void deleteChar(uint32 p);
- void clear();
- void insertChar(char c, uint32 p);
-
- void toLowercase();
- void toUppercase();
-
- uint hash() const;
-
-public:
- typedef char * iterator;
- typedef const char * const_iterator;
-
- iterator begin() {
- return _str;
- }
-
- iterator end() {
- return begin() + size();
- }
-
- const_iterator begin() const {
- return _str;
- }
-
- const_iterator end() const {
- return begin() + size();
- }
-
-protected:
- void ensureCapacity(uint32 new_len, bool keep_old);
- void incRefCount() const;
- void decRefCount(int *oldRefCount);
-};
-
-// Append two strings to form a new (temp) string
-String operator +(const String &x, const String &y);
-String operator +(const char *x, const String &y);
-String operator +(const String &x, const char *y);
-
-// Some useful additional comparision operators for Strings
-bool operator == (const char *x, const String &y);
-bool operator != (const char *x, const String &y);
-
-// Utility functions to remove leading and trailing whitespaces
-extern char *ltrim(char *t);
-extern char *rtrim(char *t);
-extern char *trim(char *t);
-
-class StringList : public Array<String> {
-public:
- void push_back(const char *str) {
- ensureCapacity(_size + 1);
- _data[_size++] = str;
- }
-
- void push_back(const String &str) {
- ensureCapacity(_size + 1);
- _data[_size++] = str;
- }
-};
-
-} // End of namespace Common
-
-#endif
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/util.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/util.h 2007-07-02 11:18:24 UTC (rev 27851)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/common/util.h 2007-07-02 13:36:53 UTC (rev 27852)
@@ -1,291 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2002-2006 The ScummVM project
- *
- * 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.
- *
- * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/common/util.h $
- * $Id: util.h 25951 2007-03-03 12:59:48Z kirben $
- */
-
-#ifndef COMMON_UTIL_H
-#define COMMON_UTIL_H
-
-#include "common/scummsys.h"
-#include "common/str.h"
-#include "common/array.h"
-
-#ifdef MIN
-#undef MIN
-#endif
-
-#ifdef MAX
-#undef MAX
-#endif
-
-template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; }
-template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; }
-template<typename T> inline T MAX (T a, T b) { return (a>b) ? a : b; }
-template<typename T> inline T CLIP (T v, T amin, T amax)
- { if (v < amin) return amin; else if (v > amax) return amax; else return v; }
-
-/**
- * Template method which swaps the vaulues of its two parameters.
- */
-template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
-
-#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
-
-namespace Common {
-
-/**
- * Print a hexdump of the data passed in. The number of bytes per line is
- * customizable.
- * @param data the data to be dumped
- * @param len the lenght of that data
- * @param bytesPerLine number of bytes to print per line (default: 16)
- */
-extern void hexdump(const byte * data, int len, int bytesPerLine = 16);
-
-/**
- * Simple random number generator. Although it is definitely not suitable for
- * cryptographic purposes, it serves our purposes just fine.
- */
-class RandomSource {
-private:
- uint32 _randSeed;
-
-public:
- RandomSource();
- void setSeed(uint32 seed);
-
- /**
- * Generates a random unsigned integer in the interval [0, max].
- * @param max the upper bound
- * @return a random number in the interval [0, max].
- */
- uint getRandomNumber(uint max);
- /**
- * Generates a random unsigned integer in the interval [min, max].
- * @param min the lower bound
- * @param max the upper bound
- * @return a random number in the interval [min, max].
- */
- uint getRandomNumberRng(uint min, uint max);
-};
-
-/**
- * List of game language.
- */
-enum Language {
- EN_ANY, // Generic English (when only one game version exist)
- EN_USA,
- EN_GRB,
-
- DE_DEU,
- FR_FRA,
- IT_ITA,
- PT_BRA,
- ES_ESP,
- JA_JPN,
- ZH_TWN,
- KO_KOR,
- SE_SWE,
- HB_ISR,
- RU_RUS,
- CZ_CZE,
- NL_NLD,
- NB_NOR,
- PL_POL,
-
- UNK_LANG = -1 // Use default language (i.e. none specified)
-};
-
-struct LanguageDescription {
- const char *code;
- const char *description;
- Common::Language id;
-};
-
-extern const LanguageDescription g_languages[];
-
-
-/** Convert a string containing a language name into a Language enum value. */
-extern Language parseLanguage(const String &str);
-extern const char *getLanguageCode(Language id);
-extern const char *getLanguageDescription(Language id);
-
-/**
- * List of game platforms. Specifying a platform for a target can be used to
- * give the game engines a hint for which platform the game data file are.
- * This may be optional or required, depending on the game engine and the
- * game in question.
- */
-enum Platform {
- kPlatformPC,
- kPlatformAmiga,
- kPlatformAtariST,
- kPlatformMacintosh,
- kPlatformFMTowns,
- kPlatformWindows,
- kPlatformNES,
- kPlatformC64,
- kPlatformLinux,
- kPlatformAcorn,
- kPlatformSegaCD,
- kPlatform3DO,
- kPlatformPCEngine,
-
- kPlatformApple2GS,
-
- kPlatformUnknown = -1
-};
-
-struct PlatformDescription {
- const char *code;
- const char *code2;
- const char *abbrev;
- const char *description;
- Common::Platform id;
-};
-
-extern const PlatformDescription g_platforms[];
-
-/** Convert a string containing a platform name into a Platform enum value. */
-extern Platform parsePlatform(const String &str);
-extern const char *getPlatformCode(Platform id);
-extern const char *getPlatformAbbrev(Platform id);
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list