[St-m-svn] SF.net SVN: st-m:[1940] trunk/src
Brought to you by:
cnx_glenn
From: <cnx...@us...> - 2011-04-02 12:40:11
|
Revision: 1940 http://st-m.svn.sourceforge.net/st-m/?rev=1940&view=rev Author: cnx_glenn Date: 2011-04-02 12:40:03 +0000 (Sat, 02 Apr 2011) Log Message: ----------- some updates Modified Paths: -------------- trunk/src/st-m_gui_qt/Resources/versioninfo.vi trunk/src/utility_classes/Util/Assert.h trunk/src/utility_classes/Util/String.h trunk/src/utility_classes/Util/WinErrorMessage.cpp trunk/src/utility_classes/Util/string_cast.cpp trunk/src/utility_classes/utility_classes.vcxproj trunk/src/utility_classes/utility_classes.vcxproj.filters Added Paths: ----------- trunk/src/utility_classes/Util/PreProcessor.h Modified: trunk/src/st-m_gui_qt/Resources/versioninfo.vi =================================================================== --- trunk/src/st-m_gui_qt/Resources/versioninfo.vi 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/st-m_gui_qt/Resources/versioninfo.vi 2011-04-02 12:40:03 UTC (rev 1940) @@ -4,7 +4,7 @@ <major>3</major> <minor>0</minor> <revision>0</revision> - <build>3449</build> + <build>3452</build> <marker>a</marker> </version> <copyright> Modified: trunk/src/utility_classes/Util/Assert.h =================================================================== --- trunk/src/utility_classes/Util/Assert.h 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/Util/Assert.h 2011-04-02 12:40:03 UTC (rev 1940) @@ -40,6 +40,11 @@ * @def REQUIRE_NOTHROW(expr) * @brief assert that \a expr does not throw an exception */ +/** + * @def REQUIRE_THROW(expr, EXCEPTION) + * @brief assert that \a expr throws an exception of type + * \a EXCEPTION + */ /** @} <!-- end of the group --> */ /** @@ -66,28 +71,43 @@ * @def VERIFY(expr) * @brief assert that \a expr is true if contracts are enabled, * evaluate \a expr if contracts are disabled + * @details Use for contracts with side effects. */ #if ((defined _DEBUG) || (defined ENABLE_CONTRACTS)) // contracts are enabled # include <boost/assert.hpp> +# include "Util/PreProcessor.h" # define REQUIRE(expr) BOOST_ASSERT(expr) # define REQUIRE_NOTHROW(expr) \ - try { (expr); BOOST_ASSERT(true); } \ - catch (...) { BOOST_ASSERT(false); } + _DO { \ + try { (expr); BOOST_ASSERT(true); } \ + catch (...) { BOOST_ASSERT(false); } \ + } _ONCE +# define REQUIRE_THROW(expr, EXCEPTION) \ + _DO { \ + try { (expr); BOOST_ASSERT(false); } \ + catch (EXCEPTION const&) { BOOST_ASSERT(true); } \ + catch (...) { BOOST_ASSERT(false); } \ + } _ONCE # define ENSURE(expr) BOOST_ASSERT(expr) # define ENSURE_NOTHROW(expr) \ - try { (expr); BOOST_ASSERT(true); } \ - catch (...) { BOOST_ASSERT(false); } + _DO { \ + try { (expr); BOOST_ASSERT(true); } \ + catch (...) { BOOST_ASSERT(false); } \ + } _ONCE # define ENSURE_THROW(expr, EXCEPTION) \ - try { (expr); BOOST_ASSERT(false); } \ - catch (EXCEPTION const&) { BOOST_ASSERT(true); } \ - catch (...) { BOOST_ASSERT(false); } + _DO { \ + try { (expr); BOOST_ASSERT(false); } \ + catch (EXCEPTION const&) { BOOST_ASSERT(true); } \ + catch (...) { BOOST_ASSERT(false); } \ + } _ONCE # define VERIFY(expr) BOOST_ASSERT(expr) #else // contracts are disabled # define REQUIRE(expr) ((void) 0) # define REQUIRE_NOTHROW(expr) ((void) 0) +# define REQUIRE_THROW(expr, EXCEPTION) ((void) 0) # define ENSURE(expr) ((void) 0) # define ENSURE_NOTHROW(expr) ((void) 0) # define ENSURE_THROW(expr, EXCEPTION) ((void) 0) Added: trunk/src/utility_classes/Util/PreProcessor.h =================================================================== --- trunk/src/utility_classes/Util/PreProcessor.h (rev 0) +++ trunk/src/utility_classes/Util/PreProcessor.h 2011-04-02 12:40:03 UTC (rev 1940) @@ -0,0 +1,52 @@ +/* + * This file is part of Startup Manager. + * Copyright (C) 2004-2011 Glenn Van Loon, gl...@st... + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/** + * @file PreProcessor.h + * @author Glenn Van Loon + * @brief contains some macros + */ + +#ifndef UTIL_PREPROCESSOR_H +#define UTIL_PREPROCESSOR_H + +/** + * @name _DO { ... } _ONCE + * @brief wrap a multi-statement macro in _DO { ... } _ONCE + * @{ + */ +/** + * @def _DO + * @brief wrap a multi-statement macro in _DO { ... } _ONCE + * @see _ONCE + */ +#define _DO \ + __pragma(warning(push)) \ + __pragma(warning(disable:4127)) \ + do +/** + * @def _ONCE + * @brief wrap a multi-statement macro in _DO { ... } _ONCE + * @see _DO + */ +#define _ONCE \ + while (false) \ + __pragma(warning(pop)) +/** @} <!-- end of the group --> */ + +#endif // UTIL_PREPROCESSOR_H Modified: trunk/src/utility_classes/Util/String.h =================================================================== --- trunk/src/utility_classes/Util/String.h 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/Util/String.h 2011-04-02 12:40:03 UTC (rev 1940) @@ -36,6 +36,11 @@ */ /** + * @namespace util::string::detail + * @brief string utilities implementation details + */ + + /** * @brief trim trailing and leading white space * @param[in] str the string to strim * @return the trimmed string Modified: trunk/src/utility_classes/Util/WinErrorMessage.cpp =================================================================== --- trunk/src/utility_classes/Util/WinErrorMessage.cpp 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/Util/WinErrorMessage.cpp 2011-04-02 12:40:03 UTC (rev 1940) @@ -17,7 +17,7 @@ */ /** - * @file WinErrorMessage.h + * @file WinErrorMessage.cpp * @author Glenn Van Loon * @brief error message implementations */ Modified: trunk/src/utility_classes/Util/string_cast.cpp =================================================================== --- trunk/src/utility_classes/Util/string_cast.cpp 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/Util/string_cast.cpp 2011-04-02 12:40:03 UTC (rev 1940) @@ -30,44 +30,48 @@ namespace util { namespace string { namespace detail { - template <typename TO, typename FROM> - TO Convert(FROM const& str) - { - typedef typename FROM::value_type FC; - typedef typename TO::value_type TC; - typedef typename FROM::size_type ST; + namespace { - typedef boost::scoped_array<TC> TCharArray; - typedef std::codecvt<FC, TC, std::mbstate_t> codecvt_t; + template <typename TO, typename FROM> + TO Convert(FROM const& str) + { + typedef typename FROM::value_type FC; + typedef typename TO::value_type TC; + typedef typename FROM::size_type ST; - codecvt_t const& cvt = std::use_facet<codecvt_t>(std::locale()); - ST bufsize = str.size()*2; - TCharArray t(new TC[bufsize]); - std::mbstate_t state = std::mbstate_t(); - FC const* nextIn = nullptr; - TC* nextOut = nullptr; + typedef boost::scoped_array<TC> TCharArray; + typedef std::codecvt<FC, TC, std::mbstate_t> codecvt_t; - for (;;) - { - switch(cvt.out(state, str.c_str(), str.c_str()+str.size(), - nextIn, t.get(), t.get()+bufsize, nextOut)) + codecvt_t const& cvt = std::use_facet<codecvt_t>(std::locale()); + ST bufsize = str.size()*2; + TCharArray t(new TC[bufsize]); + std::mbstate_t state = std::mbstate_t(); + FC const* nextIn = nullptr; + TC* nextOut = nullptr; + + for (;;) { - case std::codecvt_base::ok: - return TO(t.get(), nextOut); - case std::codecvt_base::partial: - bufsize *= 2; - t.reset(new TC[bufsize]); - continue; - case std::codecvt_base::error: - case std::codecvt_base::noconv: - TO out; - for (unsigned i = 0; i < str.size(); ++i) - out.append(1, static_cast<TC>(str[i])); - return out; + switch(cvt.out(state, str.c_str(), str.c_str()+str.size(), + nextIn, t.get(), t.get()+bufsize, nextOut)) + { + case std::codecvt_base::ok: + return TO(t.get(), nextOut); + case std::codecvt_base::partial: + bufsize *= 2; + t.reset(new TC[bufsize]); + continue; + case std::codecvt_base::error: + case std::codecvt_base::noconv: + TO out; + for (unsigned i = 0; i < str.size(); ++i) + out.append(1, static_cast<TC>(str[i])); + return out; + } } } - } + } // anonymous namespace + std::wstring ToWide(std::string const& str) { return Convert<std::wstring>(str); Modified: trunk/src/utility_classes/utility_classes.vcxproj =================================================================== --- trunk/src/utility_classes/utility_classes.vcxproj 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/utility_classes.vcxproj 2011-04-02 12:40:03 UTC (rev 1940) @@ -173,6 +173,7 @@ <ClInclude Include="Util.h" /> <ClInclude Include="Util\Assert.h" /> <ClInclude Include="Util\Command.h" /> + <ClInclude Include="Util\PreProcessor.h" /> <ClInclude Include="Util\WinErrorMessage.h" /> <ClInclude Include="Util\Exceptions.h" /> <ClInclude Include="Util\Exception\ComException.h" /> Modified: trunk/src/utility_classes/utility_classes.vcxproj.filters =================================================================== --- trunk/src/utility_classes/utility_classes.vcxproj.filters 2011-03-30 20:05:41 UTC (rev 1939) +++ trunk/src/utility_classes/utility_classes.vcxproj.filters 2011-04-02 12:40:03 UTC (rev 1940) @@ -110,6 +110,9 @@ <ClInclude Include="Util\WinErrorMessage.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="Util\PreProcessor.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="Util\Registry\RegistryKey.cpp"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |