mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Remove Vaca source code completely (replace NonCopyable class with DISABLE_COPYING macro).
This commit is contained in:
parent
b8ddd30a0d
commit
3d5fd0f07c
@ -37,7 +37,7 @@ if(MSVC)
|
||||
endif(MSVC)
|
||||
|
||||
# Third-party libraries
|
||||
set(libs3rdparty freetype jpeg libart_lgpl libpng loadpng tinyxml vaca zlib)
|
||||
set(libs3rdparty freetype jpeg libart_lgpl libpng loadpng tinyxml zlib)
|
||||
|
||||
# All libraries for .exe files
|
||||
set(all_libs aseprite-library gui-lib gfx-lib base-lib ${alleg_lib} ${libs3rdparty} ${sys_libs})
|
||||
@ -50,8 +50,7 @@ include_directories(
|
||||
${LIBPNG_DIR}
|
||||
${ZLIB_DIR}
|
||||
${LOADPNG_DIR}
|
||||
${TINYXML_DIR}
|
||||
${VACA_DIR}/include)
|
||||
${TINYXML_DIR})
|
||||
|
||||
######################################################################
|
||||
# Sub-libraries
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Vaca/String.h"
|
||||
#include "app.h"
|
||||
#include "app/color_utils.h"
|
||||
#include "ase_exception.h"
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "Vaca/String.h"
|
||||
|
||||
#include "app/color.h"
|
||||
#include "app/color_utils.h"
|
||||
#include "raster/image.h"
|
||||
|
@ -20,8 +20,8 @@
|
||||
#define CONTEXT_H_INCLUDED
|
||||
|
||||
#include <list>
|
||||
#include "Vaca/NonCopyable.h"
|
||||
#include "ase_exception.h"
|
||||
#include "base/disable_copying.h"
|
||||
#include "settings/settings.h"
|
||||
|
||||
class Sprite;
|
||||
@ -38,7 +38,7 @@ public:
|
||||
: ase_exception("Cannot execute the command because its pre-conditions are false.") { }
|
||||
};
|
||||
|
||||
class Context : Vaca::NonCopyable
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
virtual ~Context();
|
||||
@ -86,6 +86,8 @@ private:
|
||||
// Settings in this context.
|
||||
ISettings* m_settings;
|
||||
|
||||
DISABLE_COPYING(Context);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,13 +19,12 @@
|
||||
#ifndef RASTER_RGBMAP_H_INCLUDED
|
||||
#define RASTER_RGBMAP_H_INCLUDED
|
||||
|
||||
#include "Vaca/NonCopyable.h"
|
||||
#include "base/disable_copying.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
class Palette;
|
||||
|
||||
class RgbMap : public GfxObj
|
||||
, Vaca::NonCopyable
|
||||
{
|
||||
public:
|
||||
RgbMap();
|
||||
@ -38,6 +37,8 @@ public:
|
||||
|
||||
private:
|
||||
class RgbMapImpl* m_impl;
|
||||
|
||||
DISABLE_COPYING(RgbMap);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "app.h"
|
||||
#include "app/color.h"
|
||||
@ -40,6 +41,11 @@
|
||||
#include "util/boundary.h"
|
||||
#include "widgets/editor.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#undef max
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
/**********************************************************************/
|
||||
/* drawing-cursor routines */
|
||||
/**********************************************************************/
|
||||
@ -358,10 +364,10 @@ void Editor::editor_move_cursor(int x, int y, bool refresh)
|
||||
m_state != EDITOR_STATE_DRAWING) {
|
||||
Pen* pen = editor_get_current_pen();
|
||||
editors_draw_sprite(m_sprite,
|
||||
Vaca::min_value(new_x, old_x)-pen->get_size()/2,
|
||||
Vaca::min_value(new_y, old_y)-pen->get_size()/2,
|
||||
Vaca::max_value(new_x, old_x)+pen->get_size()/2,
|
||||
Vaca::max_value(new_y, old_y)+pen->get_size()/2);
|
||||
std::min(new_x, old_x)-pen->get_size()/2,
|
||||
std::min(new_y, old_y)-pen->get_size()/2,
|
||||
std::max(new_x, old_x)+pen->get_size()/2,
|
||||
std::max(new_y, old_y)+pen->get_size()/2);
|
||||
}
|
||||
|
||||
/* save area and draw the cursor */
|
||||
|
1
third_party/CMakeLists.txt
vendored
1
third_party/CMakeLists.txt
vendored
@ -13,6 +13,5 @@ add_subdirectory(libart_lgpl)
|
||||
add_subdirectory(libpng)
|
||||
add_subdirectory(loadpng)
|
||||
add_subdirectory(tinyxml)
|
||||
add_subdirectory(vaca)
|
||||
add_subdirectory(zlib)
|
||||
add_subdirectory(gtest)
|
||||
|
11
third_party/README.txt
vendored
11
third_party/README.txt
vendored
@ -46,17 +46,6 @@ lua/
|
||||
|
||||
Also, this version has a patch to make the operator != works like ~=
|
||||
|
||||
vaca/
|
||||
|
||||
This directory contains some code that is an attempt to merge Jinete
|
||||
source code (the original ASE GUI library which uses Allegro) and Vaca
|
||||
library (a Win32 wrapper).
|
||||
|
||||
Some of this code should be merge to Vaca trunk in the near future.
|
||||
See Vaca home page for more information:
|
||||
|
||||
http://vaca.sourceforge.net/
|
||||
|
||||
zlib/
|
||||
|
||||
Used by libpng. This is a shortened version of zlib 1.2.3.
|
||||
|
7
third_party/vaca/CMakeLists.txt
vendored
7
third_party/vaca/CMakeLists.txt
vendored
@ -1,7 +0,0 @@
|
||||
# ASE - Allegro Sprite Editor
|
||||
# Copyright (C) 2001-2010 David Capello
|
||||
|
||||
include_directories(include ../../src)
|
||||
|
||||
add_library(vaca
|
||||
src/Exception.cpp)
|
173
third_party/vaca/include/Vaca/Enum.h
vendored
173
third_party/vaca/include/Vaca/Enum.h
vendored
@ -1,173 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_ENUM_H
|
||||
#define VACA_ENUM_H
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4251)
|
||||
#endif
|
||||
|
||||
/**
|
||||
This class is used to define enumerations "a la" C++0x.
|
||||
|
||||
"Base" policy must be like this:
|
||||
@code
|
||||
struct Base {
|
||||
enum enumeration { ... };
|
||||
static const enumeration default_value = ...;
|
||||
};
|
||||
@endcode
|
||||
|
||||
Example of how to use this:
|
||||
@code
|
||||
struct NumbersEnum
|
||||
{
|
||||
enum enumeration {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
};
|
||||
static const enumeration default_value = Zero;
|
||||
};
|
||||
typedef Enum<NumbersEnum> Numbers;
|
||||
|
||||
main() {
|
||||
Numbers n1, n2 = Numbers::One;
|
||||
n1 = n2;
|
||||
n2 = Numbers::Two;
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
template<typename Base>
|
||||
struct Enum : public Base
|
||||
{
|
||||
typedef typename Base::enumeration enumeration;
|
||||
|
||||
Enum() : m_value(Base::default_value)
|
||||
{ }
|
||||
|
||||
Enum(enumeration value) : m_value(value)
|
||||
{ }
|
||||
|
||||
operator enumeration() const
|
||||
{ return m_value; }
|
||||
|
||||
Enum<Base> &operator=(enumeration value)
|
||||
{ m_value = value;
|
||||
return *this; }
|
||||
|
||||
private:
|
||||
enumeration m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
This class is used to define sets of enumerated values.
|
||||
|
||||
"Base" policy must be like this:
|
||||
@code
|
||||
struct Base {
|
||||
enum { ... };
|
||||
};
|
||||
@endcode
|
||||
|
||||
A EnumSet doesn't need a @c default_value like a Enum because the
|
||||
default value is zero which means: a empty set.
|
||||
|
||||
Example of how to use this:
|
||||
@code
|
||||
struct ColorsEnumSet
|
||||
{
|
||||
enum {
|
||||
Red = 1,
|
||||
Blue = 2,
|
||||
Yellow = 4,
|
||||
Magenta = Red | Blue
|
||||
};
|
||||
};
|
||||
typedef EnumSet<ColorsEnumSet> Colors;
|
||||
|
||||
main() {
|
||||
Colors red, blue, magenta;
|
||||
red = Colors::Red;
|
||||
blue = Colors::Blue;
|
||||
magenta = red | blue;
|
||||
if (magenta == Colors::Magenta) { ... }
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
template<typename Base>
|
||||
struct EnumSet : public Base
|
||||
{
|
||||
EnumSet() : m_value(0)
|
||||
{ }
|
||||
|
||||
EnumSet(int value) : m_value(value)
|
||||
{ }
|
||||
|
||||
operator int() const
|
||||
{ return m_value; }
|
||||
|
||||
EnumSet<Base> operator|(int value)
|
||||
{ return m_value | value; }
|
||||
|
||||
EnumSet<Base> operator&(int value)
|
||||
{ return m_value & value; }
|
||||
|
||||
EnumSet<Base> operator^(int value)
|
||||
{ return m_value ^ value; }
|
||||
|
||||
EnumSet<Base> &operator=(int value)
|
||||
{ m_value = value;
|
||||
return *this; }
|
||||
|
||||
EnumSet<Base> &operator|=(int value)
|
||||
{ m_value |= value;
|
||||
return *this; }
|
||||
|
||||
EnumSet<Base> &operator&=(int value)
|
||||
{ m_value &= value;
|
||||
return *this; }
|
||||
|
||||
EnumSet<Base> &operator^=(int value)
|
||||
{ m_value ^= value;
|
||||
return *this; }
|
||||
|
||||
private:
|
||||
int m_value;
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_ENUM_H
|
68
third_party/vaca/include/Vaca/Exception.h
vendored
68
third_party/vaca/include/Vaca/Exception.h
vendored
@ -1,68 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_EXCEPTION_H
|
||||
#define VACA_EXCEPTION_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <exception>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
Exception generated from Vaca.
|
||||
|
||||
Base class for every exception generated by Vaca objects.
|
||||
*/
|
||||
class VACA_DLL Exception : public std::exception
|
||||
{
|
||||
String m_message;
|
||||
int m_errorCode;
|
||||
std::string m_what;
|
||||
|
||||
public:
|
||||
|
||||
Exception();
|
||||
Exception(const String& message);
|
||||
virtual ~Exception() throw();
|
||||
|
||||
virtual const char* what() const throw();
|
||||
virtual const String& getMessage() const throw();
|
||||
|
||||
private:
|
||||
|
||||
void initialize();
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_EXCEPTION_H
|
74
third_party/vaca/include/Vaca/NonCopyable.h
vendored
74
third_party/vaca/include/Vaca/NonCopyable.h
vendored
@ -1,74 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_NONCOPYABLE_H
|
||||
#define VACA_NONCOPYABLE_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
Class which can't be copied.
|
||||
|
||||
If you derive from this class, then you will not be able to make
|
||||
copies of your own class. This means that the class will be
|
||||
copied neither using the copy constructor nor the assigment operator.
|
||||
|
||||
Example:
|
||||
@code
|
||||
class MyClass : private NonCopyable
|
||||
{
|
||||
public:
|
||||
MyClass() {
|
||||
}
|
||||
};
|
||||
int main()
|
||||
{
|
||||
MyClass a, b;
|
||||
MyClass c(a); // <-- compiler error
|
||||
b = a; // <-- compiler error
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
class VACA_DLL NonCopyable
|
||||
{
|
||||
public:
|
||||
NonCopyable() { }
|
||||
~NonCopyable() { }
|
||||
private:
|
||||
NonCopyable(const NonCopyable&);
|
||||
NonCopyable& operator=(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_NONCOPYABLE_H
|
127
third_party/vaca/include/Vaca/String.h
vendored
127
third_party/vaca/include/Vaca/String.h
vendored
@ -1,127 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_STRING_H
|
||||
#define VACA_STRING_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
@defgroup string_utils String Utilities
|
||||
@{
|
||||
*/
|
||||
|
||||
// ============================================================
|
||||
// UTILITARY
|
||||
// ============================================================
|
||||
|
||||
VACA_DLL std::string format_string(const char* fmt, ...);
|
||||
VACA_DLL std::wstring format_string(const wchar_t* fmt, ...);
|
||||
|
||||
VACA_DLL String trim_string(const String& str);
|
||||
VACA_DLL String trim_string(const Char* str);
|
||||
|
||||
VACA_DLL std::string to_utf8(const String& string);
|
||||
VACA_DLL String from_utf8(const std::string& string);
|
||||
|
||||
// Split a string in parts
|
||||
VACA_DLL void split_string(const String& string, std::vector<String>& parts, const String& separators);
|
||||
|
||||
// ============================================================
|
||||
// CONVERSION
|
||||
// ============================================================
|
||||
|
||||
// you have to use a specialization
|
||||
template<typename To, typename From>
|
||||
To convert_to(const From& from) {
|
||||
enum { not_supported = 1/(1 == 0) }; // static_assert(false)
|
||||
}
|
||||
|
||||
// convert from String
|
||||
template<> VACA_DLL std::string convert_to(const String& from);
|
||||
template<> VACA_DLL int convert_to(const String& from);
|
||||
template<> VACA_DLL long convert_to(const String& from);
|
||||
template<> VACA_DLL unsigned int convert_to(const String& from);
|
||||
template<> VACA_DLL unsigned long convert_to(const String& from);
|
||||
template<> VACA_DLL float convert_to(const String& from);
|
||||
template<> VACA_DLL double convert_to(const String& from);
|
||||
template<> VACA_DLL std::string convert_to(const Char* const& from);
|
||||
|
||||
template<> inline std::string convert_to(Char* const& from) {
|
||||
return convert_to<std::string, const Char*>(from);
|
||||
}
|
||||
|
||||
// Convert to std::string
|
||||
template<> VACA_DLL std::string convert_to(const int& from);
|
||||
|
||||
// Convert to std::wstring
|
||||
template<> VACA_DLL String convert_to(const std::string& from);
|
||||
template<> VACA_DLL String convert_to(const int& from);
|
||||
template<> VACA_DLL String convert_to(const long& from);
|
||||
template<> VACA_DLL String convert_to(const unsigned int& from);
|
||||
template<> VACA_DLL String convert_to(const unsigned long& from);
|
||||
template<> VACA_DLL String convert_to(const float& from);
|
||||
template<> VACA_DLL String convert_to(const double& from);
|
||||
template<> VACA_DLL String convert_to(const char* const& from);
|
||||
|
||||
template<> inline String convert_to(char* const& from) {
|
||||
return convert_to<String, const char*>(from);
|
||||
}
|
||||
|
||||
// Copy to a raw string
|
||||
VACA_DLL void copy_string_to(const String& src, Char* dest, int size);
|
||||
|
||||
// ============================================================
|
||||
// FILE NAMES, PATHS AND URLS
|
||||
// ============================================================
|
||||
|
||||
VACA_DLL String operator/(const String& path, const String& comp);
|
||||
VACA_DLL String& operator/=(String& path, const String& comp);
|
||||
|
||||
VACA_DLL String file_path(const String& fullpath);
|
||||
VACA_DLL String file_name(const String& fullpath);
|
||||
VACA_DLL String file_extension(const String& fullpath);
|
||||
VACA_DLL String file_title(const String& fullpath);
|
||||
|
||||
VACA_DLL String url_host(const String& url);
|
||||
VACA_DLL String url_object(const String& url);
|
||||
|
||||
VACA_DLL String encode_url(const String& url);
|
||||
VACA_DLL String decode_url(const String& url);
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_STRING_H
|
578
third_party/vaca/include/Vaca/base.h
vendored
578
third_party/vaca/include/Vaca/base.h
vendored
@ -1,578 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_BASE_H
|
||||
#define VACA_BASE_H
|
||||
|
||||
// If there are not a defined target (like VACA_WINDOWS)...
|
||||
#if !defined(VACA_WINDOWS) && \
|
||||
!defined(VACA_ALLEGRO) && \
|
||||
!defined(VACA_SDL) && \
|
||||
!defined(VACA_GTK) && \
|
||||
!defined(VACA_X11)
|
||||
// ...we define VACA_DEFAULT_PLATFORM to specify that the default
|
||||
// target will be used
|
||||
#define VACA_DEFAULT_TARGET
|
||||
#endif
|
||||
|
||||
// If we are in Windows compiler
|
||||
#if defined(_MSC_VER) || \
|
||||
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
|
||||
defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
|
||||
#ifdef VACA_DEFAULT_TARGET
|
||||
#define VACA_WINDOWS
|
||||
#endif
|
||||
// We define a macro to know that we can use Windows API
|
||||
#define VACA_ON_WINDOWS
|
||||
#else
|
||||
#ifdef VACA_DEFAULT_TARGET
|
||||
#define VACA_ALLEGRO // TODO change this to VACA_X11 when X11 support be completed
|
||||
#endif
|
||||
#define VACA_ON_UNIXLIKE
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include "Vaca/Enum.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
#define VACA_VERSION 0
|
||||
#define VACA_SUB_VERSION 0
|
||||
#define VACA_WIP_VERSION 8
|
||||
|
||||
/**
|
||||
@def VACA_DLL
|
||||
@brief Used to export/import symbols to/from the dynamic library.
|
||||
*/
|
||||
#ifdef VACA_WINDOWS
|
||||
#ifdef VACA_STATIC
|
||||
#define VACA_DLL
|
||||
#else
|
||||
#ifdef VACA_SRC
|
||||
#define VACA_DLL __declspec(dllexport)
|
||||
#else
|
||||
#define VACA_DLL __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define VACA_DLL
|
||||
#endif
|
||||
|
||||
/**
|
||||
Returns the minimum of @a x and @a y.
|
||||
|
||||
@note It is just like @b std::min, but there are problems
|
||||
in MSVC++ because a macro named @b min.
|
||||
|
||||
@see max_value, clamp_value
|
||||
*/
|
||||
template<typename T>
|
||||
inline T min_value(T x, T y)
|
||||
{
|
||||
return x < y ? x: y;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the maximum of @a x and @a y.
|
||||
|
||||
@note It is just like @b std::max, but there are problems
|
||||
in MSVC++ because a macro named @b max.
|
||||
|
||||
@see min_value, clamp_value
|
||||
*/
|
||||
template<typename T>
|
||||
inline T max_value(T x, T y)
|
||||
{
|
||||
return x > y ? x: y;
|
||||
}
|
||||
|
||||
/**
|
||||
Limits the posible values of @a x to the speficied range.
|
||||
|
||||
If @a x is great than @a high, then @a high is returned,
|
||||
if @a x is less than @a low, then @a low is returned.
|
||||
In other case, @a x is in the range, and @a x is returned.
|
||||
|
||||
@see min_value, max_value
|
||||
*/
|
||||
template<typename T>
|
||||
inline T clamp_value(T x, T low, T high)
|
||||
{
|
||||
return x > high ? high: (x < low ? low: x);
|
||||
}
|
||||
|
||||
/**
|
||||
A wide character used in a String.
|
||||
|
||||
@see String, @ref page_tn_008
|
||||
*/
|
||||
typedef wchar_t Char;
|
||||
|
||||
/**
|
||||
String type used through the Vaca API.
|
||||
|
||||
It is a std::wstring.
|
||||
|
||||
@see Char, @ref page_tn_008
|
||||
*/
|
||||
typedef std::wstring String;
|
||||
|
||||
/**
|
||||
An identifier for an application's Command.
|
||||
|
||||
@see Widget#onCommand, Command
|
||||
*/
|
||||
typedef unsigned int CommandId;
|
||||
|
||||
/**
|
||||
An identifier for a Thread.
|
||||
*/
|
||||
typedef unsigned int ThreadId;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for Orientation.
|
||||
|
||||
@see Orientation
|
||||
*/
|
||||
struct OrientationEnum
|
||||
{
|
||||
enum enumeration {
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
static const enumeration default_value = Horizontal;
|
||||
};
|
||||
|
||||
/**
|
||||
Horizontal or vertical orientation.
|
||||
|
||||
One of the following values:
|
||||
@li Orientation::Horizontal (default)
|
||||
@li Orientation::Vertical
|
||||
*/
|
||||
typedef Enum<OrientationEnum> Orientation;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for TextAlign.
|
||||
|
||||
@see TextAlign
|
||||
*/
|
||||
struct TextAlignEnum
|
||||
{
|
||||
enum enumeration {
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
};
|
||||
static const enumeration default_value = Left;
|
||||
};
|
||||
|
||||
/**
|
||||
Horizontal alignment.
|
||||
|
||||
One of the following values:
|
||||
@li TextAlign::Left (default)
|
||||
@li TextAlign::Center
|
||||
@li TextAlign::Right
|
||||
*/
|
||||
typedef Enum<TextAlignEnum> TextAlign;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for VerticalAlign.
|
||||
|
||||
@see VerticalAlign
|
||||
*/
|
||||
struct VerticalAlignEnum
|
||||
{
|
||||
enum enumeration {
|
||||
Top,
|
||||
Middle,
|
||||
Bottom
|
||||
};
|
||||
static const enumeration default_value = Top;
|
||||
};
|
||||
|
||||
/**
|
||||
Vertical alignment.
|
||||
|
||||
One of the following values:
|
||||
@li VerticalAlign::Top
|
||||
@li VerticalAlign::Middle
|
||||
@li VerticalAlign::Bottom
|
||||
*/
|
||||
typedef Enum<VerticalAlignEnum> VerticalAlign;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for Side.
|
||||
|
||||
@see Side
|
||||
*/
|
||||
struct SideEnum
|
||||
{
|
||||
enum enumeration {
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom
|
||||
};
|
||||
static const enumeration default_value = Left;
|
||||
};
|
||||
|
||||
/**
|
||||
A side.
|
||||
|
||||
One of the following values:
|
||||
@li Side::Left
|
||||
@li Side::Top
|
||||
@li Side::Right
|
||||
@li Side::Bottom
|
||||
*/
|
||||
typedef Enum<SideEnum> Side;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for Sides.
|
||||
|
||||
@see Sides
|
||||
*/
|
||||
struct SidesEnumSet
|
||||
{
|
||||
enum {
|
||||
None = 0,
|
||||
Left = 1,
|
||||
Top = 2,
|
||||
Right = 4,
|
||||
Bottom = 8,
|
||||
All = Left | Top | Right | Bottom
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
A set of sides.
|
||||
|
||||
Zero or more of the following values:
|
||||
@li Sides::Left
|
||||
@li Sides::Top
|
||||
@li Sides::Right
|
||||
@li Sides::Bottom
|
||||
*/
|
||||
typedef EnumSet<SidesEnumSet> Sides;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
It's like a namespace for CardinalDirection.
|
||||
|
||||
@see CardinalDirection
|
||||
*/
|
||||
struct CardinalDirectionEnum
|
||||
{
|
||||
enum enumeration {
|
||||
North,
|
||||
Northeast,
|
||||
East,
|
||||
Southeast,
|
||||
South,
|
||||
Southwest,
|
||||
West,
|
||||
Northwest
|
||||
};
|
||||
static const enumeration default_value = North;
|
||||
};
|
||||
|
||||
/**
|
||||
A cardinal direction.
|
||||
|
||||
One of the following values:
|
||||
@li CardinalDirection::North
|
||||
@li CardinalDirection::Northeast
|
||||
@li CardinalDirection::East
|
||||
@li CardinalDirection::Southeast
|
||||
@li CardinalDirection::South
|
||||
@li CardinalDirection::Southwest
|
||||
@li CardinalDirection::West
|
||||
@li CardinalDirection::Northwest
|
||||
*/
|
||||
typedef Enum<CardinalDirectionEnum> CardinalDirection;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
/**
|
||||
Removes an @a element from the specified STL @a container.
|
||||
|
||||
This routine removes the first ocurrence of @a element in @a container.
|
||||
It is just a helper function to avoid cryptic STL code.
|
||||
|
||||
@tparam ContainerType A STL container type.
|
||||
|
||||
@param container The container to be modified.
|
||||
@param element The element to be removed from the container.
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void remove_from_container(ContainerType& container,
|
||||
typename ContainerType::const_reference element)
|
||||
{
|
||||
for (typename ContainerType::iterator
|
||||
it = container.begin(),
|
||||
end = container.end(); it != end; ) {
|
||||
if (*it == element) {
|
||||
it = container.erase(it);
|
||||
end = container.end();
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Forward declarations
|
||||
|
||||
class Anchor;
|
||||
class AnchorLayout;
|
||||
class Application;
|
||||
class BandedDockArea;
|
||||
class BasicDockArea;
|
||||
class Bix;
|
||||
class BoxConstraint;
|
||||
class BoxLayout;
|
||||
class Brush;
|
||||
class Button;
|
||||
class ButtonBase;
|
||||
class CancelableEvent;
|
||||
class CheckBox;
|
||||
class ChildEvent;
|
||||
class ClientLayout;
|
||||
class Clipboard;
|
||||
class CloseEvent;
|
||||
class Color;
|
||||
class ColorDialog;
|
||||
class ComboBox;
|
||||
class Command;
|
||||
class CommandEvent;
|
||||
class CommandsClient;
|
||||
class CommonDialog;
|
||||
class Component;
|
||||
class ConditionVariable;
|
||||
class Constraint;
|
||||
class Cursor;
|
||||
class CustomButton;
|
||||
class CustomLabel;
|
||||
class Dialog;
|
||||
class DockArea;
|
||||
class DockBar;
|
||||
class DockFrame;
|
||||
class DockInfo;
|
||||
class DragListBox;
|
||||
class DropFilesEvent;
|
||||
class Event;
|
||||
class Exception;
|
||||
class FileDialog;
|
||||
class FindTextDialog;
|
||||
class FocusEvent;
|
||||
class Font;
|
||||
class FontDialog;
|
||||
class FontMetrics;
|
||||
class Frame;
|
||||
class Graphics;
|
||||
class GraphicsPath;
|
||||
class GroupBox;
|
||||
class HttpRequest;
|
||||
class HttpRequestException;
|
||||
class Icon;
|
||||
class Image;
|
||||
class ImageHandle;
|
||||
class ImageList;
|
||||
class ImagePixels;
|
||||
class KeyEvent;
|
||||
class Label;
|
||||
class Layout;
|
||||
class LayoutEvent;
|
||||
class LinkLabel;
|
||||
class ListBox;
|
||||
class ListColumn;
|
||||
class ListItem;
|
||||
class ListView;
|
||||
class ListViewEvent;
|
||||
class MdiChild;
|
||||
class MdiClient;
|
||||
class MdiFrame;
|
||||
class MdiListMenu;
|
||||
class Menu;
|
||||
class MenuBar;
|
||||
class MenuItem;
|
||||
class MenuItemEvent;
|
||||
class MenuSeparator;
|
||||
class Message;
|
||||
class MouseEvent;
|
||||
class MsgBox;
|
||||
class Node;
|
||||
class NonCopyable;
|
||||
class OpenFileDialog;
|
||||
class PaintEvent;
|
||||
class Pen;
|
||||
class PopupMenu;
|
||||
class PreferredSizeEvent;
|
||||
class ProgressBar;
|
||||
class Property;
|
||||
class RadioButton;
|
||||
class RadioGroup;
|
||||
class ReBar;
|
||||
class ReBarBand;
|
||||
class Referenceable;
|
||||
class Region;
|
||||
class ResizeEvent;
|
||||
class ResourceId;
|
||||
class SaveFileDialog;
|
||||
class SciEdit;
|
||||
class SciRegister;
|
||||
class ScreenGraphics;
|
||||
class ScrollEvent;
|
||||
class ScrollInfo;
|
||||
class Separator;
|
||||
class SetCursorEvent;
|
||||
class Slider;
|
||||
class SpinButton;
|
||||
class Spinner;
|
||||
class SplitBar;
|
||||
class StatusBar;
|
||||
class System;
|
||||
class Tab;
|
||||
class TabBase;
|
||||
class TabPage;
|
||||
class TextEdit;
|
||||
class Thread;
|
||||
class TimePoint;
|
||||
class Timer;
|
||||
class ToggleButton;
|
||||
class ToolBar;
|
||||
class ToolButton;
|
||||
class ToolSet;
|
||||
class TreeNode;
|
||||
class TreeView;
|
||||
class TreeViewEvent;
|
||||
class TreeViewIterator;
|
||||
class Widget;
|
||||
class WidgetClassName;
|
||||
|
||||
template<class T>
|
||||
class SharedPtr;
|
||||
|
||||
// ======================================================================
|
||||
// Smart Pointers
|
||||
|
||||
/**
|
||||
@defgroup smart_pointers Smart Pointers
|
||||
@{
|
||||
*/
|
||||
|
||||
typedef SharedPtr<Anchor> AnchorPtr;
|
||||
typedef SharedPtr<AnchorLayout> AnchorLayoutPtr;
|
||||
typedef SharedPtr<BandedDockArea> BandedDockAreaPtr;
|
||||
typedef SharedPtr<BasicDockArea> BasicDockAreaPtr;
|
||||
typedef SharedPtr<Bix> BixPtr;
|
||||
typedef SharedPtr<BoxConstraint> BoxConstraintPtr;
|
||||
typedef SharedPtr<BoxLayout> BoxLayoutPtr;
|
||||
typedef SharedPtr<Button> ButtonPtr;
|
||||
typedef SharedPtr<ButtonBase> ButtonBasePtr;
|
||||
typedef SharedPtr<CheckBox> CheckBoxPtr;
|
||||
typedef SharedPtr<ClientLayout> ClientLayoutPtr;
|
||||
typedef SharedPtr<ColorDialog> ColorDialogPtr;
|
||||
typedef SharedPtr<ComboBox> ComboBoxPtr;
|
||||
typedef SharedPtr<Command> CommandPtr;
|
||||
typedef SharedPtr<CommonDialog> CommonDialogPtr;
|
||||
typedef SharedPtr<Component> ComponentPtr;
|
||||
typedef SharedPtr<Constraint> ConstraintPtr;
|
||||
typedef SharedPtr<CustomButton> CustomButtonPtr;
|
||||
typedef SharedPtr<CustomLabel> CustomLabelPtr;
|
||||
typedef SharedPtr<Dialog> DialogPtr;
|
||||
typedef SharedPtr<DockArea> DockAreaPtr;
|
||||
typedef SharedPtr<DockBar> DockBarPtr;
|
||||
typedef SharedPtr<DockFrame> DockFramePtr;
|
||||
typedef SharedPtr<DockInfo> DockInfoPtr;
|
||||
typedef SharedPtr<DragListBox> DragListBoxPtr;
|
||||
typedef SharedPtr<FileDialog> FileDialogPtr;
|
||||
typedef SharedPtr<FindTextDialog> FindTextDialogPtr;
|
||||
typedef SharedPtr<FontDialog> FontDialogPtr;
|
||||
typedef SharedPtr<Frame> FramePtr;
|
||||
typedef SharedPtr<GroupBox> GroupBoxPtr;
|
||||
typedef SharedPtr<Label> LabelPtr;
|
||||
typedef SharedPtr<Layout> LayoutPtr;
|
||||
typedef SharedPtr<LinkLabel> LinkLabelPtr;
|
||||
typedef SharedPtr<ListBox> ListBoxPtr;
|
||||
typedef SharedPtr<ListItem> ListItemPtr;
|
||||
typedef SharedPtr<ListView> ListViewPtr;
|
||||
typedef SharedPtr<MdiChild> MdiChildPtr;
|
||||
typedef SharedPtr<MdiClient> MdiClientPtr;
|
||||
typedef SharedPtr<MdiFrame> MdiFramePtr;
|
||||
typedef SharedPtr<MdiListMenu> MdiListMenuPtr;
|
||||
typedef SharedPtr<Menu> MenuPtr;
|
||||
typedef SharedPtr<MenuBar> MenuBarPtr;
|
||||
typedef SharedPtr<MenuItem> MenuItemPtr;
|
||||
typedef SharedPtr<MenuSeparator> MenuSeparatorPtr;
|
||||
typedef SharedPtr<OpenFileDialog> OpenFileDialogPtr;
|
||||
typedef SharedPtr<PopupMenu> PopupMenuPtr;
|
||||
typedef SharedPtr<ProgressBar> ProgressBarPtr;
|
||||
typedef SharedPtr<Property> PropertyPtr;
|
||||
typedef SharedPtr<RadioButton> RadioButtonPtr;
|
||||
typedef SharedPtr<ReBar> ReBarPtr;
|
||||
typedef SharedPtr<SaveFileDialog> SaveFileDialogPtr;
|
||||
typedef SharedPtr<SciEdit> SciEditPtr;
|
||||
typedef SharedPtr<Separator> SeparatorPtr;
|
||||
typedef SharedPtr<Slider> SliderPtr;
|
||||
typedef SharedPtr<SpinButton> SpinButtonPtr;
|
||||
typedef SharedPtr<Spinner> SpinnerPtr;
|
||||
typedef SharedPtr<SplitBar> SplitBarPtr;
|
||||
typedef SharedPtr<StatusBar> StatusBarPtr;
|
||||
typedef SharedPtr<Tab> TabPtr;
|
||||
typedef SharedPtr<TabBase> TabBasePtr;
|
||||
typedef SharedPtr<TabPage> TabPagePtr;
|
||||
typedef SharedPtr<TextEdit> TextEditPtr;
|
||||
typedef SharedPtr<ToggleButton> ToggleButtonPtr;
|
||||
typedef SharedPtr<ToolBar> ToolBarPtr;
|
||||
typedef SharedPtr<ToolSet> ToolSetPtr;
|
||||
typedef SharedPtr<TreeNode> TreeNodePtr;
|
||||
typedef SharedPtr<TreeView> TreeViewPtr;
|
||||
typedef SharedPtr<Widget> WidgetPtr;
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_BASE_H
|
71
third_party/vaca/include/Vaca/main.h
vendored
71
third_party/vaca/include/Vaca/main.h
vendored
@ -1,71 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_MAIN_H
|
||||
#define VACA_MAIN_H
|
||||
|
||||
#include "Vaca/Application.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// WinMain for Win32
|
||||
|
||||
#if defined(VACA_WINDOWS)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
int PASCAL WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
Vaca::details::MainArgs::setArgs(NULL, NULL);
|
||||
return vaca_main();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// main()/END_OF_MAIN() for Allegro 4.2
|
||||
|
||||
#elif defined(VACA_ALLEGRO)
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Vaca::details::MainArgs::setArgs(argc, argv);
|
||||
return vaca_main();
|
||||
}
|
||||
|
||||
END_OF_MAIN();
|
||||
|
||||
#endif
|
||||
|
||||
#endif // VACA_MAIN_H
|
143
third_party/vaca/src/Exception.cpp
vendored
143
third_party/vaca/src/Exception.cpp
vendored
@ -1,143 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/Exception.h"
|
||||
#include "Vaca/String.h"
|
||||
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <lmerr.h>
|
||||
#include <wininet.h>
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
/**
|
||||
Creates generic exception with an empty error message.
|
||||
*/
|
||||
Exception::Exception()
|
||||
: std::exception()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an exception with the specified error message.
|
||||
|
||||
@param message Error message.
|
||||
*/
|
||||
Exception::Exception(const String& message)
|
||||
: std::exception()
|
||||
, m_message(message)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the exception.
|
||||
*/
|
||||
Exception::~Exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a printable C-string of the error.
|
||||
|
||||
It could contain more information about the error than just the
|
||||
specified "message" in the constructor.
|
||||
|
||||
@win32
|
||||
The @msdn{GetLastError} is used to get more information about
|
||||
the error.
|
||||
@endwin32
|
||||
*/
|
||||
const char* Exception::what() const throw()
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the message specified in the constructor or an empty string
|
||||
if the default constructor was used.
|
||||
*/
|
||||
const String& Exception::getMessage() const throw()
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
void Exception::initialize()
|
||||
{
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
HMODULE hmodule = NULL;
|
||||
DWORD flags =
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
LPSTR msgbuf = NULL;
|
||||
|
||||
m_errorCode = GetLastError();
|
||||
|
||||
// is it an network-error?
|
||||
if (m_errorCode >= NERR_BASE && m_errorCode <= MAX_NERR) {
|
||||
hmodule = LoadLibraryExA("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (hmodule)
|
||||
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
||||
}
|
||||
else if (m_errorCode >= INTERNET_ERROR_BASE && m_errorCode <= INTERNET_ERROR_LAST) {
|
||||
hmodule = LoadLibraryExA("wininet.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (hmodule)
|
||||
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
||||
}
|
||||
|
||||
// get the error message in ASCII
|
||||
if (!FormatMessageA(flags,
|
||||
hmodule,
|
||||
m_errorCode,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPSTR>(&msgbuf),
|
||||
0, NULL)) {
|
||||
// error we can't load the string
|
||||
msgbuf = NULL;
|
||||
}
|
||||
|
||||
if (hmodule)
|
||||
FreeLibrary(hmodule);
|
||||
|
||||
m_what += convert_to<std::string>(format_string(L"%d", m_errorCode));
|
||||
m_what += " - ";
|
||||
if (msgbuf) {
|
||||
m_what += msgbuf;
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
m_what += convert_to<std::string>(m_message);
|
||||
#endif
|
||||
}
|
394
third_party/vaca/src/String.cpp
vendored
394
third_party/vaca/src/String.cpp
vendored
@ -1,394 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/String.h"
|
||||
#include "Vaca/Exception.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <vector>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
std::string Vaca::format_string(const char* fmt, ...)
|
||||
{
|
||||
std::auto_ptr<char> buf;
|
||||
int size = 512;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<char>(new char[size <<= 1]);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
int written = _vsnprintf(buf.get(), size, fmt, ap);
|
||||
#elif defined(VACA_ON_UNIXLIKE)
|
||||
int written = vsnprintf(buf.get(), size, fmt, ap);
|
||||
#else
|
||||
#error Implement this in your platform
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
if (written == size) {
|
||||
if (buf.get()[size] == 0)
|
||||
break;
|
||||
}
|
||||
else if (written >= 0 && written < size) {
|
||||
assert(buf.get()[written] == 0);
|
||||
break;
|
||||
}
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return std::string(buf.get());
|
||||
}
|
||||
|
||||
std::wstring Vaca::format_string(const wchar_t* fmt, ...)
|
||||
{
|
||||
std::auto_ptr<wchar_t> buf;
|
||||
int size = 512;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<wchar_t>(new wchar_t[size <<= 1]);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
int written = _vsnwprintf(buf.get(), size, fmt, ap);
|
||||
#elif defined(VACA_ON_UNIXLIKE)
|
||||
int written = vswprintf(buf.get(), size, fmt, ap);
|
||||
#else
|
||||
#error Implement this in your platform
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
if (written == size) {
|
||||
if (buf.get()[size] == 0)
|
||||
break;
|
||||
}
|
||||
else if (written >= 0 && written < size) {
|
||||
assert(buf.get()[written] == 0);
|
||||
break;
|
||||
}
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return std::wstring(buf.get());
|
||||
}
|
||||
|
||||
String Vaca::trim_string(const String& str)
|
||||
{
|
||||
return trim_string(str.c_str());
|
||||
}
|
||||
|
||||
String Vaca::trim_string(const Char* str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
|
||||
String res(str);
|
||||
while (!res.empty() && std::isspace(res.at(0)))
|
||||
res.erase(res.begin());
|
||||
while (!res.empty() && std::isspace(res.at(res.size()-1)))
|
||||
res.erase(res.end()-1);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<> int Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (int)std::wcstol(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> long Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (long)std::wcstol(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> unsigned int Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (unsigned int)std::wcstoul(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> unsigned long Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (unsigned long)std::wcstoul(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> float Vaca::convert_to(const String& from)
|
||||
{
|
||||
return static_cast<float>(std::wcstod(from.c_str(), NULL));
|
||||
}
|
||||
|
||||
template<> double Vaca::convert_to(const String& from)
|
||||
{
|
||||
return std::wcstod(from.c_str(), NULL);
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const int& from)
|
||||
{
|
||||
return format_string("%d", from);
|
||||
}
|
||||
|
||||
template<> std::wstring Vaca::convert_to(const int& from)
|
||||
{
|
||||
return format_string(L"%d", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const long& from)
|
||||
{
|
||||
return format_string(L"%ld", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const unsigned int& from)
|
||||
{
|
||||
return format_string(L"%u", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const unsigned long& from)
|
||||
{
|
||||
return format_string(L"%lu", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const float& from)
|
||||
{
|
||||
return format_string(L"%.16g", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const double& from)
|
||||
{
|
||||
return format_string(L"%.16g", from);
|
||||
}
|
||||
|
||||
/**
|
||||
Commondly used to give strings to Win32 API or from Win32 API (in
|
||||
structures and messages).
|
||||
*/
|
||||
void Vaca::copy_string_to(const String& src, Char* dest, int size)
|
||||
{
|
||||
std::wcsncpy(dest, src.c_str(), size);
|
||||
dest[size-1] = L'\0';
|
||||
}
|
||||
|
||||
/**
|
||||
Concatenates two path components.
|
||||
|
||||
It is useful if the string represent a path and we have to add a
|
||||
file name. For example:
|
||||
@code
|
||||
String path(L"C:\\myproject\\src");
|
||||
assert(path / L"main.h" == L"C:\\myproject\\src\\main.h");
|
||||
@endcode
|
||||
|
||||
@param component
|
||||
The string to be added at the end of the string
|
||||
(separated by a slash).
|
||||
*/
|
||||
String Vaca::operator/(const String& path, const String& comp)
|
||||
{
|
||||
String res(path);
|
||||
|
||||
if (!res.empty() && *(res.end()-1) != L'/' && *(res.end()-1) != L'\\')
|
||||
res.push_back(L'\\');
|
||||
|
||||
res += comp;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a path component at the end of the path.
|
||||
|
||||
It is useful if the string represent a path and we have to add a
|
||||
file name. For example:
|
||||
@code
|
||||
String path(L"C:\\myproject\\src");
|
||||
path /= L"main.h";
|
||||
assert(path == L"C:\\myproject\\src\\main.h");
|
||||
@endcode
|
||||
|
||||
@param component
|
||||
The string to be added at the end of the string
|
||||
(separated by a slash).
|
||||
*/
|
||||
String& Vaca::operator/=(String& path, const String& comp)
|
||||
{
|
||||
if (!path.empty() && *(path.end()-1) != L'/' && *(path.end()-1) != L'\\')
|
||||
path.push_back(L'\\');
|
||||
|
||||
path += comp;
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file path (the path of "C:\foo\main.cpp" is "C:\foo"
|
||||
without the file name).
|
||||
|
||||
@see file_name
|
||||
*/
|
||||
String Vaca::file_path(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit)
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
|
||||
if (rit != fullpath.rend()) {
|
||||
++rit;
|
||||
std::copy(fullpath.begin(), String::const_iterator(rit.base()),
|
||||
std::back_inserter(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file name (the file name of "C:\foo\main.cpp" is
|
||||
"main.cpp", without the path).
|
||||
|
||||
@see file_path, file_title
|
||||
*/
|
||||
String Vaca::file_name(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit)
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
|
||||
std::copy(String::const_iterator(rit.base()), fullpath.end(),
|
||||
std::back_inserter(res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file extension (the extension of "C:\foo\main.cpp" is
|
||||
"cpp", without the path and its title).
|
||||
|
||||
@warning
|
||||
For a file name like "pack.tar.gz" the extension is "gz".
|
||||
|
||||
@see file_path, file_title
|
||||
*/
|
||||
String Vaca::file_extension(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
// search for the first dot from the end of the string
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit) {
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
return res;
|
||||
else if (*rit == L'.')
|
||||
break;
|
||||
}
|
||||
|
||||
if (rit != fullpath.rend()) {
|
||||
std::copy(String::const_iterator(rit.base()), fullpath.end(),
|
||||
std::back_inserter(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file title (the title of "C:\foo\main.cpp" is "main",
|
||||
without the path and without the extension).
|
||||
|
||||
@warning
|
||||
For a file name like "pack.tar.gz" the title is "pack.tar".
|
||||
|
||||
@see file_path, file_extension
|
||||
*/
|
||||
String Vaca::file_title(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String::const_iterator last_dot = fullpath.end();
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit) {
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
else if (*rit == L'.' && last_dot == fullpath.end())
|
||||
last_dot = rit.base()-1;
|
||||
}
|
||||
|
||||
for (String::const_iterator it(rit.base()); it!=fullpath.end(); ++it) {
|
||||
if (it == last_dot)
|
||||
break;
|
||||
else
|
||||
res.push_back(*it);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
String Vaca::url_host(const String& url)
|
||||
{
|
||||
String host;
|
||||
int len = url.size();
|
||||
for (int c=0; c<len; ++c) {
|
||||
if (url[c] == L':' && url[c+1] == L'/' && url[c+2] == L'/') {
|
||||
for (c+=3; c<len && url[c] != L'/'; ++c)
|
||||
host.push_back(url[c]);
|
||||
}
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
String Vaca::url_object(const String& url)
|
||||
{
|
||||
String object;
|
||||
int len = url.size();
|
||||
for (int c=0; c<len; ++c) {
|
||||
if (url[c] == ':' && url[c+1] == '/' && url[c+2] == '/') {
|
||||
for (c+=3; c<len && url[c] != '/'; ++c)
|
||||
;
|
||||
for (; c<len; ++c)
|
||||
object.push_back(url[c]);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
#include "win32/String.h"
|
||||
#elif defined(VACA_ALLEGRO)
|
||||
#include "allegro/String.h"
|
||||
#endif
|
81
third_party/vaca/src/allegro/String.h
vendored
81
third_party/vaca/src/allegro/String.h
vendored
@ -1,81 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
// TODO
|
||||
// std::string Vaca::to_utf8(const String& string);
|
||||
// String Vaca::from_utf8(const std::string& string);
|
||||
|
||||
template<> std::string Vaca::convert_to(const Char* const& from)
|
||||
{
|
||||
int len = std::wcslen(from)+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
if (uconvert((const char*)from, U_UNICODE, ansiBuf.get(), U_ASCII, len))
|
||||
return std::string(ansiBuf.get());
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const String& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
if (uconvert((const char*)from.c_str(), U_UNICODE, ansiBuf.get(), U_ASCII, len))
|
||||
return std::string(ansiBuf.get());
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const char* const& from)
|
||||
{
|
||||
int len = strlen(from)+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
if (uconvert(from, U_ASCII, (char*)wideBuf.get(), U_UNICODE, len))
|
||||
return String(wideBuf.get());
|
||||
else
|
||||
return L"";
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const std::string& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
if (uconvert(from.c_str(), U_ASCII, (char*)wideBuf.get(), U_UNICODE, len))
|
||||
return String(wideBuf.get());
|
||||
else
|
||||
return L"";
|
||||
}
|
||||
|
||||
// TODO
|
||||
// String Vaca::encode_url(const String& url);
|
||||
// String Vaca::decode_url(const String& url);
|
||||
|
158
third_party/vaca/src/win32/String.h
vendored
158
third_party/vaca/src/win32/String.h
vendored
@ -1,158 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
std::string Vaca::to_utf8(const String& string)
|
||||
{
|
||||
int required_size =
|
||||
WideCharToMultiByte(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
NULL, 0, NULL, NULL);
|
||||
|
||||
if (required_size == 0)
|
||||
return std::string();
|
||||
|
||||
std::vector<char> buf(++required_size);
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
&buf[0], required_size,
|
||||
NULL, NULL);
|
||||
|
||||
return std::string(&buf[0]);
|
||||
}
|
||||
|
||||
String Vaca::from_utf8(const std::string& string)
|
||||
{
|
||||
int required_size =
|
||||
MultiByteToWideChar(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
NULL, 0);
|
||||
|
||||
if (required_size == 0)
|
||||
return String();
|
||||
|
||||
std::vector<wchar_t> buf(++required_size);
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
&buf[0], required_size);
|
||||
|
||||
return String(&buf[0]);
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const Char* const& from)
|
||||
{
|
||||
int len = std::wcslen(from)+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
int ret = WideCharToMultiByte(CP_ACP, 0, from, len, ansiBuf.get(), len, NULL, NULL);
|
||||
if (ret == 0)
|
||||
return "";
|
||||
else
|
||||
return std::string(ansiBuf.get());
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const String& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
int ret = WideCharToMultiByte(CP_ACP, 0, from.c_str(), len, ansiBuf.get(), len, NULL, NULL);
|
||||
if (ret == 0)
|
||||
return "";
|
||||
else
|
||||
return std::string(ansiBuf.get());
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const char* const& from)
|
||||
{
|
||||
int len = strlen(from)+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
int ret = MultiByteToWideChar(CP_ACP, 0, from, len, wideBuf.get(), len);
|
||||
if (ret == 0)
|
||||
return L"";
|
||||
else
|
||||
return String(wideBuf.get());
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const std::string& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
int ret = MultiByteToWideChar(CP_ACP, 0, from.c_str(), len, wideBuf.get(), len);
|
||||
if (ret == 0)
|
||||
return L"";
|
||||
else
|
||||
return String(wideBuf.get());
|
||||
}
|
||||
|
||||
String Vaca::encode_url(const String& url)
|
||||
{
|
||||
std::auto_ptr<Char> buf;
|
||||
DWORD size = 1024;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<Char>(new Char[size]);
|
||||
|
||||
if (::InternetCanonicalizeUrlW(url.c_str(), buf.get(), &size, 0))
|
||||
break;
|
||||
|
||||
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
throw Exception(); // TODO improve the exception type/information
|
||||
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return String(buf.get());
|
||||
}
|
||||
|
||||
String Vaca::decode_url(const String& url)
|
||||
{
|
||||
std::auto_ptr<Char> buf;
|
||||
DWORD size = 1024;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<Char>(new Char[size]);
|
||||
|
||||
if (::InternetCanonicalizeUrlW(url.c_str(), buf.get(), &size,
|
||||
ICU_DECODE | ICU_NO_ENCODE))
|
||||
break;
|
||||
|
||||
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
throw Exception(); // TODO improve the exception type/information
|
||||
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return String(buf.get());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user