diff options
author | Karlson2k <k2k@narod.ru> | 2014-06-30 19:30:13 +0400 |
---|---|---|
committer | Karlson2k <k2k@narod.ru> | 2014-07-02 14:18:12 +0400 |
commit | a0bdc7f67c5d2f8f1133c51328212670c831b359 (patch) | |
tree | e611cb160e7c1e3f593c69739526c0220d2df402 | |
parent | 2a7c4e4906640e236292bb535e2af59308195858 (diff) |
Move class auto_buffer to separate file
-rw-r--r-- | XBMC.xcodeproj/project.pbxproj | 10 | ||||
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj | 2 | ||||
-rw-r--r-- | project/VS2010Express/XBMC.vcxproj.filters | 6 | ||||
-rw-r--r-- | xbmc/filesystem/File.cpp | 59 | ||||
-rw-r--r-- | xbmc/filesystem/File.h | 29 | ||||
-rw-r--r-- | xbmc/utils/Makefile.in | 1 | ||||
-rw-r--r-- | xbmc/utils/auto_buffer.cpp | 85 | ||||
-rw-r--r-- | xbmc/utils/auto_buffer.h | 53 |
8 files changed, 159 insertions, 86 deletions
diff --git a/XBMC.xcodeproj/project.pbxproj b/XBMC.xcodeproj/project.pbxproj index 5f7c9c05b1..94f85ee888 100644 --- a/XBMC.xcodeproj/project.pbxproj +++ b/XBMC.xcodeproj/project.pbxproj @@ -284,6 +284,9 @@ 7C8FC6EE1829A4580045153D /* DirectoryProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FC6EC1829A4580045153D /* DirectoryProvider.cpp */; }; 7C8FC6EF1829A4580045153D /* DirectoryProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FC6EC1829A4580045153D /* DirectoryProvider.cpp */; }; 7C8FC6F01829A4580045153D /* DirectoryProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FC6EC1829A4580045153D /* DirectoryProvider.cpp */; }; + 7C908894196358A8003D0619 /* auto_buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C908892196358A8003D0619 /* auto_buffer.cpp */; }; + 7C908895196358A8003D0619 /* auto_buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C908892196358A8003D0619 /* auto_buffer.cpp */; }; + 7C908896196358A8003D0619 /* auto_buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C908892196358A8003D0619 /* auto_buffer.cpp */; }; 7C920CF9181669FF00DA1477 /* TextureOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C920CF7181669FF00DA1477 /* TextureOperations.cpp */; }; 7C920CFA181669FF00DA1477 /* TextureOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C920CF7181669FF00DA1477 /* TextureOperations.cpp */; }; 7C920CFB181669FF00DA1477 /* TextureOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C920CF7181669FF00DA1477 /* TextureOperations.cpp */; }; @@ -4206,6 +4209,8 @@ 7C8AE853189DE47700C33786 /* CoreAudioHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioHelpers.h; path = Sinks/osx/CoreAudioHelpers.h; sourceTree = "<group>"; }; 7C8FC6EC1829A4580045153D /* DirectoryProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DirectoryProvider.cpp; path = xbmc/listproviders/DirectoryProvider.cpp; sourceTree = SOURCE_ROOT; }; 7C8FC6ED1829A4580045153D /* DirectoryProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DirectoryProvider.h; path = xbmc/listproviders/DirectoryProvider.h; sourceTree = SOURCE_ROOT; }; + 7C908892196358A8003D0619 /* auto_buffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = auto_buffer.cpp; sourceTree = "<group>"; }; + 7C908893196358A8003D0619 /* auto_buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = auto_buffer.h; sourceTree = "<group>"; }; 7C920CF7181669FF00DA1477 /* TextureOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureOperations.cpp; sourceTree = "<group>"; }; 7C920CF8181669FF00DA1477 /* TextureOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureOperations.h; sourceTree = "<group>"; }; 7C99B6A2133D342100FC2B16 /* CircularCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CircularCache.cpp; sourceTree = "<group>"; }; @@ -9697,6 +9702,8 @@ E38E1E260D25F9FD00618676 /* Archive.h */, F5FDF51C0E7218950005B0A6 /* AsyncFileCopy.cpp */, F5FDF51B0E7218950005B0A6 /* AsyncFileCopy.h */, + 7C908892196358A8003D0619 /* auto_buffer.cpp */, + 7C908893196358A8003D0619 /* auto_buffer.h */, F5BDB81F120203C200F0B710 /* AutoPtrHandle.cpp */, F5BDB81E120203C200F0B710 /* AutoPtrHandle.h */, DF52769A151BAEDA00B5B63B /* Base64.cpp */, @@ -11850,6 +11857,7 @@ 7CAA469019427AED00008885 /* PosixDirectory.cpp in Sources */, DF033D381946612400BFC82E /* AEDeviceEnumerationOSX.cpp in Sources */, 7C525DF5195E2D8100BE3482 /* SaveFileStateJob.cpp in Sources */, + 7C908894196358A8003D0619 /* auto_buffer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -13043,6 +13051,7 @@ 7CCDACCC19275D790074CF51 /* NptAppleLogConfig.mm in Sources */, 7CAA469219427AED00008885 /* PosixDirectory.cpp in Sources */, 7C525DF7195E2D8100BE3482 /* SaveFileStateJob.cpp in Sources */, + 7C908896196358A8003D0619 /* auto_buffer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -14238,6 +14247,7 @@ 7CCDACCB19275D790074CF51 /* NptAppleLogConfig.mm in Sources */, 7CAA469119427AED00008885 /* PosixDirectory.cpp in Sources */, 7C525DF6195E2D8100BE3482 /* SaveFileStateJob.cpp in Sources */, + 7C908895196358A8003D0619 /* auto_buffer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index 8048de99ef..aafc4f1447 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -970,6 +970,7 @@ <ClInclude Include="..\..\xbmc\settings\windows\GUIWindowSettingsScreenCalibration.h" /> <ClInclude Include="..\..\xbmc\settings\windows\GUIWindowTestPattern.h" /> <ClInclude Include="..\..\xbmc\utils\ActorProtocol.h" /> + <ClInclude Include="..\..\xbmc\utils\auto_buffer.h" /> <ClInclude Include="..\..\xbmc\utils\BooleanLogic.h" /> <ClInclude Include="..\..\xbmc\utils\CharsetDetection.h" /> <ClInclude Include="..\..\xbmc\utils\IRssObserver.h" /> @@ -1111,6 +1112,7 @@ <ClInclude Include="..\..\xbmc\interfaces\json-rpc\AddonsOperations.h" /> <ClCompile Include="..\..\xbmc\ThumbLoader.cpp" /> <ClCompile Include="..\..\xbmc\utils\ActorProtocol.cpp" /> + <ClCompile Include="..\..\xbmc\utils\auto_buffer.cpp" /> <ClCompile Include="..\..\xbmc\utils\BooleanLogic.cpp" /> <ClCompile Include="..\..\xbmc\utils\CharsetDetection.cpp" /> <ClCompile Include="..\..\xbmc\utils\LegacyPathTranslation.cpp" /> diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index 5d8181125f..3ca760a921 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -3071,6 +3071,9 @@ <Filter>filesystem\win32</Filter> </ClCompile> <ClCompile Include="..\..\xbmc\CompileInfo.cpp" /> + <ClCompile Include="..\..\xbmc\utils\auto_buffer.cpp"> + <Filter>utils</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\xbmc\win32\pch.h"> @@ -6016,6 +6019,9 @@ <Filter>filesystem\win32</Filter> </ClInclude> <ClInclude Include="..\..\xbmc\CompileInfo.h" /> + <ClInclude Include="..\..\xbmc\utils\auto_buffer.h"> + <Filter>utils</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc"> diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index 24fa4f0ccf..e59cfbd7c6 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -69,65 +69,6 @@ CFile::~CFile() //********************************************************************************************* -auto_buffer::auto_buffer(size_t size) : p(NULL), s(0) -{ - if (!size) - return; - - p = malloc(size); - if (!p) - throw std::bad_alloc(); - s = size; -} - -auto_buffer::~auto_buffer() -{ - clear(); -} - -auto_buffer& auto_buffer::allocate(size_t size) -{ - clear(); - return resize(size); -} - -auto_buffer& auto_buffer::resize(size_t newSize) -{ - void* newPtr = realloc(p, newSize); - if (!newPtr && newSize) - throw std::bad_alloc(); - p = newPtr; - s = newSize; - return *this; -} - -auto_buffer& auto_buffer::clear(void) -{ - free(p); - p = NULL; - s = 0; - return *this; -} - -auto_buffer& auto_buffer::attach(void* pointer, size_t size) -{ - clear(); - if ((pointer && size) || (!pointer && !size)) - { - p = pointer; - s = size; - } - return *this; -} - -void* auto_buffer::detach(void) -{ - void* returnPtr = p; - p = NULL; - s = 0; - return returnPtr; -} - bool CFile::Copy(const CStdString& strFileName, const CStdString& strDest, XFILE::IFileCallback* pCallback, void* pContext) { const CURL pathToUrl(strFileName); diff --git a/xbmc/filesystem/File.h b/xbmc/filesystem/File.h index 0b52234562..cc033c183d 100644 --- a/xbmc/filesystem/File.h +++ b/xbmc/filesystem/File.h @@ -30,6 +30,7 @@ #pragma once #include <iostream> +#include "utils/auto_buffer.h" #include "utils/StdString.h" #include "IFileTypes.h" #include "PlatformDefs.h" @@ -40,6 +41,7 @@ class CURL; namespace XFILE { +using ::XUTILS::auto_buffer; class IFile; class IFileCallback @@ -69,33 +71,6 @@ public: class CFileStreamBuffer; -class auto_buffer -{ -public: - auto_buffer(void) : p(NULL), s(0) - { } - explicit auto_buffer(size_t size); - ~auto_buffer(); - - auto_buffer& allocate(size_t size); - auto_buffer& resize(size_t newSize); - auto_buffer& clear(void); - - inline char* get(void) const { return static_cast<char*>(p); } - inline size_t size(void) const { return s; } - inline size_t length(void) const { return s; } - - auto_buffer& attach(void* pointer, size_t size); - void* detach(void); - -private: - auto_buffer(const auto_buffer& other); // disallow copy constructor - auto_buffer& operator=(const auto_buffer& other); // disallow assignment - - void* p; - size_t s; -}; - class CFile { public: diff --git a/xbmc/utils/Makefile.in b/xbmc/utils/Makefile.in index 85d5111049..de33bb40ea 100644 --- a/xbmc/utils/Makefile.in +++ b/xbmc/utils/Makefile.in @@ -3,6 +3,7 @@ SRCS += AliasShortcutUtils.cpp SRCS += Archive.cpp SRCS += AsyncFileCopy.cpp SRCS += AutoPtrHandle.cpp +SRCS += auto_buffer.cpp SRCS += Base64.cpp SRCS += BitstreamConverter.cpp SRCS += BitstreamStats.cpp diff --git a/xbmc/utils/auto_buffer.cpp b/xbmc/utils/auto_buffer.cpp new file mode 100644 index 0000000000..cee06a239d --- /dev/null +++ b/xbmc/utils/auto_buffer.cpp @@ -0,0 +1,85 @@ +/* +* Copyright (C) 2013-2014 Team XBMC +* http://xbmc.org +* +* 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, 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 XBMC; see the file COPYING. If not, see +* <http://www.gnu.org/licenses/>. +* +*/ + +#include "auto_buffer.h" +#include <new> // for std::bad_alloc +#include <stdlib.h> // for malloc(), realloc() and free() + +using namespace XUTILS; + +auto_buffer::auto_buffer(size_t size) : p(NULL), s(0) +{ + if (!size) + return; + + p = malloc(size); + if (!p) + throw std::bad_alloc(); + s = size; +} + +auto_buffer::~auto_buffer() +{ + clear(); +} + +auto_buffer& auto_buffer::allocate(size_t size) +{ + clear(); + return resize(size); +} + +auto_buffer& auto_buffer::resize(size_t newSize) +{ + void* newPtr = realloc(p, newSize); + if (!newPtr && newSize) + throw std::bad_alloc(); + p = newPtr; + s = newSize; + return *this; +} + +auto_buffer& auto_buffer::clear(void) +{ + free(p); + p = NULL; + s = 0; + return *this; +} + +auto_buffer& auto_buffer::attach(void* pointer, size_t size) +{ + clear(); + if ((pointer && size) || (!pointer && !size)) + { + p = pointer; + s = size; + } + return *this; +} + +void* auto_buffer::detach(void) +{ + void* returnPtr = p; + p = NULL; + s = 0; + return returnPtr; +} + diff --git a/xbmc/utils/auto_buffer.h b/xbmc/utils/auto_buffer.h new file mode 100644 index 0000000000..5008b47ef6 --- /dev/null +++ b/xbmc/utils/auto_buffer.h @@ -0,0 +1,53 @@ +#pragma once +/* +* Copyright (C) 2013-2014 Team XBMC +* http://xbmc.org +* +* 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, 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 XBMC; see the file COPYING. If not, see +* <http://www.gnu.org/licenses/>. +* +*/ + +#include <stddef.h> // for size_t + +namespace XUTILS +{ + + class auto_buffer + { + public: + auto_buffer(void) : p(NULL), s(0) + {} + explicit auto_buffer(size_t size); + ~auto_buffer(); + + auto_buffer& allocate(size_t size); + auto_buffer& resize(size_t newSize); + auto_buffer& clear(void); + + inline char* get(void) const { return static_cast<char*>(p); } + inline size_t size(void) const { return s; } + inline size_t length(void) const { return s; } + + auto_buffer& attach(void* pointer, size_t size); + void* detach(void); + + private: + auto_buffer(const auto_buffer& other); // disallow copy constructor + auto_buffer& operator=(const auto_buffer& other); // disallow assignment + + void* p; + size_t s; + }; +} |