mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-01 01:13:40 +00:00
Remove Vaca::Application class. Move Vaca::String class to src/base/string.h (and split_string and convert_to algorithms to src/base/).
This commit is contained in:
parent
5ccddbc8bc
commit
818e286c84
11
src/app.cpp
11
src/app.cpp
@ -110,7 +110,7 @@ static TabsBarHandler* tabsHandler = NULL;
|
||||
|
||||
// Initializes the application loading the modules, setting the
|
||||
// graphics mode, loading the configuration and resources, etc.
|
||||
App::App()
|
||||
App::App(int argc, char* argv[])
|
||||
: m_configModule(NULL)
|
||||
, m_checkArgs(NULL)
|
||||
, m_loggerModule(NULL)
|
||||
@ -121,8 +121,11 @@ App::App()
|
||||
ASSERT(m_instance == NULL);
|
||||
m_instance = this;
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
m_args.push_back(argv[i]);
|
||||
|
||||
m_configModule = new ConfigModule();
|
||||
m_checkArgs = new CheckArgs();
|
||||
m_checkArgs = new CheckArgs(m_args);
|
||||
m_loggerModule = new LoggerModule(m_checkArgs->isVerbose());
|
||||
m_modules = new Modules();
|
||||
m_isGui = !(m_checkArgs->isConsoleOnly());
|
||||
@ -243,7 +246,7 @@ int App::run()
|
||||
|
||||
case CheckArgs::Option::OpenSprite: {
|
||||
/* load the sprite */
|
||||
Sprite* sprite = sprite_load(Vaca::convert_to<std::string>(option->data()).c_str());
|
||||
Sprite* sprite = sprite_load(option->data().c_str());
|
||||
if (!sprite) {
|
||||
if (!isGui())
|
||||
console.printf("Error loading file \"%s\"\n", option->data().c_str());
|
||||
@ -259,7 +262,7 @@ int App::run()
|
||||
set_sprite_in_more_reliable_editor(context->get_first_sprite());
|
||||
|
||||
// Recent file
|
||||
getRecentFiles()->addRecentFile(Vaca::convert_to<std::string>(option->data()).c_str());
|
||||
getRecentFiles()->addRecentFile(option->data().c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define APP_H_INCLUDED
|
||||
|
||||
#include "base/signal.h"
|
||||
#include "base/string.h"
|
||||
#include "gui/jbase.h"
|
||||
|
||||
#include <vector>
|
||||
@ -41,11 +42,16 @@ class ToolBox;
|
||||
class App
|
||||
{
|
||||
public:
|
||||
App();
|
||||
App(int argc, char* argv[]);
|
||||
~App();
|
||||
|
||||
static App* instance() { return m_instance; }
|
||||
|
||||
// Functions to get the arguments specified in the command line.
|
||||
int getArgc() const { return m_args.size(); }
|
||||
const base::string& getArgv(int i) { return m_args[i]; }
|
||||
const std::vector<base::string>& getArgs() const { return m_args; }
|
||||
|
||||
// Returns true if ASE is running with GUI available.
|
||||
bool isGui() const { return m_isGui; }
|
||||
|
||||
@ -75,6 +81,7 @@ private:
|
||||
Modules* m_modules;
|
||||
LegacyModules* m_legacy;
|
||||
bool m_isGui;
|
||||
std::vector<base::string> m_args;
|
||||
};
|
||||
|
||||
void app_refresh_screen(const Sprite* sprite);
|
||||
|
@ -2,6 +2,7 @@
|
||||
# Copyright (C) 2001-2010 David Capello
|
||||
|
||||
add_library(base-lib
|
||||
convert_to.cpp
|
||||
errno_string.cpp
|
||||
mem_utils.cpp
|
||||
mutex.cpp)
|
||||
|
23
src/base/convert_to.cpp
Normal file
23
src/base/convert_to.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "base/convert_to.h"
|
||||
|
||||
template<> int base::convert_to(const base::string& from)
|
||||
{
|
||||
return std::strtol(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> base::string base::convert_to(const int& from)
|
||||
{
|
||||
char buf[32];
|
||||
std::sprintf(buf, "%d", from);
|
||||
return buf;
|
||||
}
|
25
src/base/convert_to.h
Normal file
25
src/base/convert_to.h
Normal file
@ -0,0 +1,25 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_CONVERT_TO_H_INCLUDED
|
||||
#define BASE_CONVERT_TO_H_INCLUDED
|
||||
|
||||
#include "base/string.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
// Undefined convertion
|
||||
template<typename To, typename From>
|
||||
To convert_to(const From& from) {
|
||||
enum { not_supported = 1/(1 == 0) }; // static_assert(false)
|
||||
}
|
||||
|
||||
template<> int convert_to(const base::string& from);
|
||||
template<> base::string convert_to(const int& from);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
57
src/base/split_string.h
Normal file
57
src/base/split_string.h
Normal file
@ -0,0 +1,57 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_SPLIT_STRING_H_INCLUDED
|
||||
#define BASE_SPLIT_STRING_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace details {
|
||||
|
||||
template<class T>
|
||||
struct is_separator {
|
||||
const T* separators;
|
||||
is_separator(const T* separators) : separators(separators) { }
|
||||
bool operator()(typename T::value_type chr)
|
||||
{
|
||||
for (typename T::const_iterator
|
||||
it = separators->begin(),
|
||||
end = separators->end(); it != end; ++it) {
|
||||
if (chr == *it)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void split_string(const T& string, std::vector<T>& parts, const T& separators)
|
||||
{
|
||||
size_t elements = 1 + std::count_if(string.begin(), string.end(), details::is_separator<T>(&separators));
|
||||
parts.reserve(elements);
|
||||
|
||||
size_t beg = 0, end;
|
||||
while (true) {
|
||||
end = string.find_first_of(separators, beg);
|
||||
if (end != T::npos) {
|
||||
parts.push_back(string.substr(beg, end - beg));
|
||||
beg = end+1;
|
||||
}
|
||||
else {
|
||||
parts.push_back(string.substr(beg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
47
src/base/split_string_unittest.cpp
Normal file
47
src/base/split_string_unittest.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#include "tests/test.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/split_string.h"
|
||||
|
||||
TEST(SplitString, Empty)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
base::split_string<std::string>("", result, ",");
|
||||
ASSERT_EQ(1, result.size());
|
||||
EXPECT_EQ("", result[0]);
|
||||
}
|
||||
|
||||
TEST(SplitString, NoSeparator)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
base::split_string<std::string>("Hello,World", result, "");
|
||||
ASSERT_EQ(1, result.size());
|
||||
EXPECT_EQ("Hello,World", result[0]);
|
||||
}
|
||||
|
||||
TEST(SplitString, OneSeparator)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
base::split_string<std::string>("Hello,World", result, ",");
|
||||
ASSERT_EQ(2, result.size());
|
||||
EXPECT_EQ("Hello", result[0]);
|
||||
EXPECT_EQ("World", result[1]);
|
||||
}
|
||||
|
||||
TEST(SplitString, MultipleSeparators)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
base::split_string<std::string>("Hello,World", result, ",r");
|
||||
ASSERT_EQ(3, result.size());
|
||||
EXPECT_EQ("Hello", result[0]);
|
||||
EXPECT_EQ("Wo", result[1]);
|
||||
EXPECT_EQ("ld", result[2]);
|
||||
}
|
18
src/base/string.h
Normal file
18
src/base/string.h
Normal file
@ -0,0 +1,18 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_STRING_H_INCLUDED
|
||||
#define BASE_STRING_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace base {
|
||||
|
||||
typedef std::string string;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -18,21 +18,17 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "Vaca/Application.h"
|
||||
#include "Vaca/String.h"
|
||||
|
||||
#include "base/convert_to.h"
|
||||
#include "base/split_string.h"
|
||||
#include "base/string.h"
|
||||
#include "check_args.h"
|
||||
#include "console.h"
|
||||
#include "core/cfg.h"
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
CheckArgs::CheckArgs()
|
||||
CheckArgs::CheckArgs(const std::vector<base::string>& args)
|
||||
: m_consoleOnly(false)
|
||||
, m_verbose(false)
|
||||
{
|
||||
const std::vector<String>& args(Application::getArgs());
|
||||
|
||||
// Exe name
|
||||
m_exeName = args[0];
|
||||
|
||||
@ -41,40 +37,40 @@ CheckArgs::CheckArgs()
|
||||
size_t i, n, len;
|
||||
|
||||
for (i=1; i<args.size(); i++) {
|
||||
const String& arg(args[i]);
|
||||
const base::string& arg(args[i]);
|
||||
|
||||
for (n=0; arg[n] == '-'; n++);
|
||||
len = arg.size()-n;
|
||||
|
||||
// Option
|
||||
if ((n > 0) && (len > 0)) {
|
||||
String option = arg.substr(n);
|
||||
base::string option = arg.substr(n);
|
||||
|
||||
// Use other palette file
|
||||
if (option == L"palette") {
|
||||
if (option == "palette") {
|
||||
if (++i < args.size())
|
||||
m_paletteFilename = args[i];
|
||||
else
|
||||
usage(false);
|
||||
}
|
||||
// Video resolution
|
||||
else if (option == L"resolution") {
|
||||
else if (option == "resolution") {
|
||||
if (++i < args.size()) {
|
||||
// The following argument should indicate the resolution
|
||||
// in a format like: 320x240[x8]
|
||||
std::vector<String> parts;
|
||||
split_string(args[i], parts, L"x");
|
||||
std::vector<base::string> parts;
|
||||
base::split_string<base::string>(args[i], parts, "x");
|
||||
|
||||
switch (parts.size()) {
|
||||
case 1:
|
||||
set_config_int("GfxMode", "Depth", convert_to<double>(parts[0]));
|
||||
set_config_int("GfxMode", "Depth", base::convert_to<int>(parts[0]));
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
set_config_int("GfxMode", "Width", convert_to<double>(parts[0]));
|
||||
set_config_int("GfxMode", "Height", convert_to<double>(parts[1]));
|
||||
set_config_int("GfxMode", "Width", base::convert_to<int>(parts[0]));
|
||||
set_config_int("GfxMode", "Height", base::convert_to<int>(parts[1]));
|
||||
if (parts.size() == 3)
|
||||
set_config_int("GfxMode", "Depth", convert_to<double>(parts[2]));
|
||||
set_config_int("GfxMode", "Depth", base::convert_to<int>(parts[2]));
|
||||
break;
|
||||
default:
|
||||
usage(false);
|
||||
@ -88,15 +84,15 @@ CheckArgs::CheckArgs()
|
||||
}
|
||||
}
|
||||
// Verbose mode
|
||||
else if (option == L"verbose") {
|
||||
else if (option == "verbose") {
|
||||
m_verbose = true;
|
||||
}
|
||||
// Show help
|
||||
else if (option == L"help") {
|
||||
else if (option == "help") {
|
||||
usage(true);
|
||||
}
|
||||
// Show version
|
||||
else if (option == L"version") {
|
||||
else if (option == "version") {
|
||||
m_consoleOnly = true;
|
||||
console.printf("%s %s\n", PACKAGE, VERSION);
|
||||
}
|
||||
|
@ -19,10 +19,8 @@
|
||||
#ifndef CHECK_ARGS_H_INCLUDED
|
||||
#define CHECK_ARGS_H_INCLUDED
|
||||
|
||||
#include "Vaca/String.h"
|
||||
#include <vector>
|
||||
|
||||
using Vaca::String;
|
||||
#include "base/string.h"
|
||||
|
||||
// Parses the input arguments in the command line.
|
||||
class CheckArgs
|
||||
@ -33,23 +31,23 @@ public:
|
||||
class Option
|
||||
{
|
||||
int m_type;
|
||||
String m_data;
|
||||
base::string m_data;
|
||||
|
||||
public:
|
||||
enum {
|
||||
OpenSprite,
|
||||
};
|
||||
|
||||
Option(int type, const String& data) : m_type(type), m_data(data) { }
|
||||
Option(int type, const base::string& data) : m_type(type), m_data(data) { }
|
||||
|
||||
int type() const { return m_type; }
|
||||
const String& data() const { return m_data; }
|
||||
const base::string& data() const { return m_data; }
|
||||
};
|
||||
|
||||
typedef std::vector<Option*> Options;
|
||||
typedef Options::iterator iterator;
|
||||
|
||||
CheckArgs();
|
||||
CheckArgs(const std::vector<base::string>& args);
|
||||
~CheckArgs();
|
||||
|
||||
void clear();
|
||||
@ -57,7 +55,7 @@ public:
|
||||
iterator begin() { return m_options.begin(); }
|
||||
iterator end() { return m_options.end(); }
|
||||
|
||||
String getPaletteFilename() const { return m_paletteFilename; }
|
||||
base::string getPaletteFilename() const { return m_paletteFilename; }
|
||||
|
||||
bool isConsoleOnly() const { return m_consoleOnly; }
|
||||
bool isVerbose() const { return m_verbose; }
|
||||
@ -66,8 +64,8 @@ private:
|
||||
void usage(bool showHelp);
|
||||
|
||||
Options m_options;
|
||||
String m_paletteFilename;
|
||||
String m_exeName;
|
||||
base::string m_paletteFilename;
|
||||
base::string m_exeName;
|
||||
bool m_consoleOnly;
|
||||
bool m_verbose;
|
||||
};
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <Vaca/String.h>
|
||||
|
||||
#include "base/convert_to.h"
|
||||
#include "base/string.h"
|
||||
#include "commands/command.h"
|
||||
#include "launcher.h"
|
||||
|
||||
@ -87,11 +88,11 @@ void CheckUpdatesCommand::onExecute(Context* context)
|
||||
// Version of the operating system
|
||||
if (os_version >= 0) {
|
||||
url += "&osver=";
|
||||
url += Vaca::convert_to<std::string>(os_version);
|
||||
url += base::convert_to<base::string>(os_version);
|
||||
}
|
||||
if (os_revision >= 0) {
|
||||
url += "&osrev=";
|
||||
url += Vaca::convert_to<std::string>(os_revision);
|
||||
url += base::convert_to<base::string>(os_revision);
|
||||
}
|
||||
|
||||
Launcher::openUrl(url);
|
||||
|
17
src/main.cpp
17
src/main.cpp
@ -25,6 +25,10 @@
|
||||
#include "app.h"
|
||||
#include "loadpng.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winalleg.h>
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Information for "ident".
|
||||
|
||||
@ -56,15 +60,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// ASE entry point (this function is called from Vaca library)
|
||||
int vaca_main()
|
||||
// ASE entry point
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef WIN32
|
||||
CoInitialize(NULL);
|
||||
#endif
|
||||
|
||||
int status = 1; // 1 = error
|
||||
Allegro allegro;
|
||||
|
||||
try {
|
||||
Jinete jinete;
|
||||
App app;
|
||||
App app(argc, argv);
|
||||
|
||||
status = app.run();
|
||||
}
|
||||
@ -83,4 +91,5 @@ int vaca_main()
|
||||
return status;
|
||||
}
|
||||
|
||||
#include "Vaca/main.h"
|
||||
END_OF_MAIN();
|
||||
|
||||
|
5
third_party/vaca/CMakeLists.txt
vendored
5
third_party/vaca/CMakeLists.txt
vendored
@ -4,12 +4,9 @@
|
||||
include_directories(include ../../src)
|
||||
|
||||
add_library(vaca
|
||||
src/Application.cpp
|
||||
src/Component.cpp
|
||||
src/Event.cpp
|
||||
src/Exception.cpp
|
||||
src/PreferredSizeEvent.cpp
|
||||
src/Property.cpp
|
||||
src/Referenceable.cpp
|
||||
src/String.cpp
|
||||
src/Vaca.cpp)
|
||||
src/Referenceable.cpp)
|
||||
|
86
third_party/vaca/include/Vaca/Application.h
vendored
86
third_party/vaca/include/Vaca/Application.h
vendored
@ -1,86 +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_APPLICATION_H
|
||||
#define VACA_APPLICATION_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
namespace details {
|
||||
class VACA_DLL MainArgs
|
||||
{
|
||||
public:
|
||||
static void setArgs(int, char**);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
The main class of Vaca: initializes and destroys the GUI library
|
||||
resources.
|
||||
|
||||
A program that uses Vaca library must to create one instance of
|
||||
this class, or an instance of a derived class.
|
||||
*/
|
||||
class VACA_DLL Application
|
||||
{
|
||||
public:
|
||||
|
||||
Application();
|
||||
virtual ~Application();
|
||||
|
||||
static size_t getArgc();
|
||||
static const String& getArgv(size_t i);
|
||||
static const std::vector<String>& getArgs();
|
||||
|
||||
static Application* getInstance();
|
||||
|
||||
private:
|
||||
|
||||
friend class details::MainArgs;
|
||||
|
||||
/**
|
||||
The singleton, the only instance of Application (or a class
|
||||
derived from Application) that a program can contain.
|
||||
*/
|
||||
static Application* m_instance;
|
||||
|
||||
static std::vector<String> m_args;
|
||||
|
||||
static void setArgs(const std::vector<String>& args);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_APPLICATION_H
|
91
third_party/vaca/src/Application.cpp
vendored
91
third_party/vaca/src/Application.cpp
vendored
@ -1,91 +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/Application.h"
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
Application* Application::m_instance = NULL;
|
||||
std::vector<String> Application::m_args;
|
||||
|
||||
Application::Application()
|
||||
{
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
CoInitialize(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
}
|
||||
|
||||
size_t Application::getArgc()
|
||||
{
|
||||
return m_args.size();
|
||||
}
|
||||
|
||||
const String& Application::getArgv(size_t i)
|
||||
{
|
||||
return m_args[i];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the parameters in the command line.
|
||||
|
||||
@c Application::getArgs()[0] is the name of the executable file.
|
||||
*/
|
||||
const std::vector<String>& Application::getArgs()
|
||||
{
|
||||
return m_args;
|
||||
}
|
||||
|
||||
void Application::setArgs(const std::vector<String>& args)
|
||||
{
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the Application's singleton.
|
||||
|
||||
A program using Vaca must have one instance of Applicaton or a
|
||||
class derived from it.
|
||||
*/
|
||||
Application* Application::getInstance()
|
||||
{
|
||||
assert(m_instance != NULL);
|
||||
return m_instance;
|
||||
}
|
37
third_party/vaca/src/String.cpp
vendored
37
third_party/vaca/src/String.cpp
vendored
@ -128,43 +128,6 @@ String Vaca::trim_string(const Char* str)
|
||||
return res;
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct is_separator
|
||||
{
|
||||
const String* separators;
|
||||
is_separator(const String* separators) : separators(separators) { }
|
||||
bool operator()(Char chr)
|
||||
{
|
||||
for (String::const_iterator
|
||||
it = separators->begin(),
|
||||
end = separators->end(); it != end; ++it) {
|
||||
if (chr == *it)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Vaca::split_string(const String& string, std::vector<String>& parts, const String& separators)
|
||||
{
|
||||
size_t elements = 1 + std::count_if(string.begin(), string.end(), is_separator(&separators));
|
||||
parts.resize(elements);
|
||||
|
||||
size_t beg = 0, end;
|
||||
while (true) {
|
||||
end = string.find_first_of(separators);
|
||||
if (end != String::npos) {
|
||||
parts.push_back(string.substr(beg, end - beg));
|
||||
beg = end+1;
|
||||
}
|
||||
else {
|
||||
parts.push_back(string.substr(beg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<> int Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (int)std::wcstol(from.c_str(), NULL, 10);
|
||||
|
39
third_party/vaca/src/Vaca.cpp
vendored
39
third_party/vaca/src/Vaca.cpp
vendored
@ -1,39 +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/base.h"
|
||||
#include "Vaca/Application.h"
|
||||
|
||||
#if defined(VACA_WINDOWS)
|
||||
#include "win32/MainArgs.h"
|
||||
#else
|
||||
#include "std/MainArgs.h"
|
||||
#endif
|
42
third_party/vaca/src/std/MainArgs.h
vendored
42
third_party/vaca/src/std/MainArgs.h
vendored
@ -1,42 +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"
|
||||
|
||||
void Vaca::details::MainArgs::setArgs(int argc, char* argv[])
|
||||
{
|
||||
std::vector<String> args;
|
||||
args.reserve(argc);
|
||||
for (int i=0; i<argc; ++i)
|
||||
args.push_back(convert_to<String>(argv[i]));
|
||||
|
||||
Application::setArgs(args);
|
||||
}
|
51
third_party/vaca/src/win32/MainArgs.h
vendored
51
third_party/vaca/src/win32/MainArgs.h
vendored
@ -1,51 +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 <windows.h>
|
||||
|
||||
void Vaca::details::MainArgs::setArgs(int, char**)
|
||||
{
|
||||
// Convert the command-line to a vector of arguments using Win32 API
|
||||
std::vector<String> args;
|
||||
LPWSTR* arglist;
|
||||
int argc;
|
||||
|
||||
arglist = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||
if (arglist != NULL) {
|
||||
args.reserve(argc);
|
||||
for (int i=0; i<argc; ++i)
|
||||
args.push_back(arglist[i]);
|
||||
|
||||
::LocalFree(arglist);
|
||||
}
|
||||
|
||||
Application::setArgs(args);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user