windows live writer test

   1: /***********************************************************************
   2:     filename:     CEGUIDefaultResourceProvider.cpp
   3:     created:    8/7/2004
   4:     author:        James '_mental_' O'Sullivan
   5:     
   6:     purpose:    Implements the Resource Manager common functionality
   7: *************************************************************************/
   8: /***************************************************************************
   9:  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
  10:  *
  11:  *   Permission is hereby granted, free of charge, to any person obtaining
  12:  *   a copy of this software and associated documentation files (the
  13:  *   "Software"), to deal in the Software without restriction, including
  14:  *   without limitation the rights to use, copy, modify, merge, publish,
  15:  *   distribute, sublicense, and/or sell copies of the Software, and to
  16:  *   permit persons to whom the Software is furnished to do so, subject to
  17:  *   the following conditions:
  18:  *
  19:  *   The above copyright notice and this permission notice shall be
  20:  *   included in all copies or substantial portions of the Software.
  21:  *
  22:  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23:  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24:  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25:  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  26:  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  27:  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28:  *   OTHER DEALINGS IN THE SOFTWARE.
  29:  ***************************************************************************/
  30: #include "CEGUIDefaultResourceProvider.h"
  31: #include "CEGUIExceptions.h"
  32:  
  33: #include 
   
   
  34: #include 
   
   
  35:  
  36: // Start of CEGUI namespace section
  37: namespace CEGUI
  38: {
  39:  
  40:     void DefaultResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup)
  41:     {
  42:         if (filename.empty())
  43:         {
  44:             throw InvalidRequestException(
  45:                 "DefaultResourceProvider::load - Filename supplied for data loading must be valid");
  46:         }
  47:  
  48:         String final_filename(getFinalFilename(filename, resourceGroup));
  49:          
  50:         std::ifstream dataFile(final_filename.c_str(), std::ios::binary|std::ios::ate);
  51:         if( dataFile.fail())
  52:         {
  53:             throw InvalidRequestException(
  54:                 "DefaultResourceProvider::load - " + filename + " does not exist");
  55:         }
  56:         std::streampos size = dataFile.tellg();
  57:         dataFile.seekg (0, std::ios::beg);
  58:  
  59:         unsigned char* buffer = new unsigned char [size];
  60:  
  61:         try {
  62:             dataFile.read(reinterpret_cast<char*>(buffer), size);
  63:         }
  64:         catch(std::ifstream::failure e) {
  65:             delete [] buffer;
  66:             throw GenericException(
  67:                 "DefaultResourceProvider::loadRawDataContainer - Problem reading " + filename);
  68:         }
  69:  
  70:         dataFile.close();
  71:  
  72:         output.setData(buffer);
  73:         output.setSize(size);
  74:     }
  75:     
  76:     void DefaultResourceProvider::unloadRawDataContainer(RawDataContainer& data)
  77:     {
  78:         uint8* ptr = data.getDataPtr();
  79:         delete [] ptr;
  80:         data.setData(0);
  81:         data.setSize(0);
  82:     }
  83:  
  84:     void DefaultResourceProvider::setResourceGroupDirectory(const String& resourceGroup, const String& directory)
  85:     {
  86:         d_resourceGroups[resourceGroup] = directory;
  87:     }
  88:  
  89:     const String& DefaultResourceProvider::getResourceGroupDirectory(const String& resourceGroup)
  90:     {
  91:         return d_resourceGroups[resourceGroup];
  92:     }
  93:  
  94:     void DefaultResourceProvider::clearResourceGroupDirectory(const String& resourceGroup)
  95:     {
  96:         ResourceGroupMap::iterator iter = d_resourceGroups.find(resourceGroup);
  97:  
  98:         if (iter != d_resourceGroups.end())
  99:             d_resourceGroups.erase(iter);
 100:     }
 101:  
 102:     String DefaultResourceProvider::getFinalFilename(const String& filename, const String& resourceGroup) const
 103:     {
 104:         String final_filename;
 105:  
 106:         // look up resource group directory
 107:         ResourceGroupMap::const_iterator iter =
 108:             d_resourceGroups.find(resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup);
 109:  
 110:         // if there was an entry for this group, use it's directory as the
 111:         // first part of the filename
 112:         if (iter != d_resourceGroups.end())
 113:             final_filename = (*iter).second;
 114:  
 115:         // append the filename part that we were passed
 116:         final_filename += filename;
 117:  
 118:         // return result
 119:         return final_filename;
 120:     }
 121:  
 122: } // End of  CEGUI namespace section
Hydrangeas
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值