Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/gui/OgreCEGUIResourceProvider.cpp @ 2258

Last change on this file since 2258 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/************************************************************************
2    filename:   OgreCEGUIResourceProvider.cpp
3    created:    8/7/2004
4    author:             James '_mental_' O'Sullivan
5
6    purpose:    Implements the Resource Provider common functionality
7*************************************************************************/
8/*************************************************************************
9    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26#include "OrxonoxStableHeaders.h"
27#include "OgreCEGUIResourceProvider.h"
28
29#include <CEGUIExceptions.h>
30#include <OgreArchiveManager.h>
31
32
33// Start of CEGUI namespace section
34namespace CEGUI
35{
36    OgreCEGUIResourceProvider::OgreCEGUIResourceProvider() : ResourceProvider()
37    {
38        // set deafult resource group for Ogre
39        d_defaultResourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str();
40    }
41
42//    void OgreResourceProvider::loadInputSourceContainer(const String& filename, InputSourceContainer& output)
43//   {
44//        Ogre::DataStreamPtr input = Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str());
45//
46//              if (input.isNull())
47//              {
48//                      throw InvalidRequestException((utf8*)
49//                              "Scheme::Scheme - Filename supplied for Scheme loading must be valid");
50//              }
51//
52//       XERCES_CPP_NAMESPACE_USE
53//        size_t buffsz = input->size();
54//        unsigned char* mem = reinterpret_cast<unsigned char*>(XMLPlatformUtils::fgArrayMemoryManager->allocate(buffsz));
55//        memcpy(mem, input.getPointer()->getAsString().c_str(), buffsz);
56//        InputSource* mInputSource = new MemBufInputSource(mem, buffsz, filename.c_str(), true);
57//        input.setNull();
58//
59//       output.setData(mInputSource);
60//    }
61
62    void OgreCEGUIResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output,  const String& resourceGroup)
63    {
64        String orpGroup;
65        if (resourceGroup.empty())
66            orpGroup = d_defaultResourceGroup.empty() ? Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() : d_defaultResourceGroup;
67        else
68            orpGroup = resourceGroup;
69
70        Ogre::DataStreamPtr input =
71            Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str(), orpGroup.c_str());
72
73        if (input.isNull())
74        {
75            throw InvalidRequestException((utf8*)
76                "OgreCEGUIResourceProvider::loadRawDataContainer - Unable to open resource file '" + filename + (utf8*)"' in resource group '" + orpGroup + (utf8*)"'.");
77        }
78
79        Ogre::String buf = input->getAsString();
80        const size_t memBuffSize = buf.length();
81
82        unsigned char* mem = new unsigned char[memBuffSize];
83        memcpy(mem, buf.c_str(), memBuffSize);
84
85        output.setData(mem);
86        output.setSize(memBuffSize);
87    }
88
89    void OgreCEGUIResourceProvider::unloadRawDataContainer(RawDataContainer& data)
90    {
91        if (data.getDataPtr())
92        {
93            delete[] data.getDataPtr();
94            data.setData(0);
95            data.setSize(0);
96        }
97    }
98} // End of  CEGUI namespace section
Note: See TracBrowser for help on using the repository browser.