Don't wrap the default config json blobs in std::strings

This commit is contained in:
Thomas Goyne 2014-03-21 14:02:49 -07:00
parent d615dcb30a
commit e1bc828e44
10 changed files with 22 additions and 24 deletions

View File

@ -49,7 +49,7 @@ void Hotkey::ComboInsert(Combo const& combo) {
cmd_map.insert(make_pair(combo.CmdName(), combo));
}
Hotkey::Hotkey(agi::fs::path const& file, const std::string &default_config)
Hotkey::Hotkey(agi::fs::path const& file, std::pair<const char *, size_t> default_config)
: config_file(file)
{
LOG_D("hotkey/init") << "Generating hotkeys.";

View File

@ -48,23 +48,23 @@ json::UnknownElement file(agi::fs::path const& file) {
return parse(*io::Open(file));
}
json::UnknownElement file(agi::fs::path const& file, const std::string &default_config) {
json::UnknownElement file(agi::fs::path const& file, std::pair<const char *, size_t> default_config) {
try {
return parse(*io::Open(file));
}
catch (fs::FileNotFound const&) {
// Not an error
boost::interprocess::ibufferstream stream(default_config.data(), default_config.size());
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
return parse(stream);
}
catch (json::Exception&) {
// Already logged in parse
boost::interprocess::ibufferstream stream(default_config.data(), default_config.size());
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
return parse(stream);
}
catch (agi::Exception& e) {
LOG_E("json/file") << "Unexpected error when reading config file " << file << ": " << e.GetMessage();
boost::interprocess::ibufferstream stream(default_config.data(), default_config.size());
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
return parse(stream);
}
}

View File

@ -32,7 +32,7 @@
namespace agi {
MRUManager::MRUManager(agi::fs::path const& config, std::string const& default_config, agi::Options *options)
MRUManager::MRUManager(agi::fs::path const& config, std::pair<const char *, size_t> default_config, agi::Options *options)
: config_name(config)
, options(options)
{

View File

@ -67,12 +67,12 @@ namespace {
namespace agi {
Options::Options(agi::fs::path const& file, const std::string& default_config, const OptionSetting setting)
Options::Options(agi::fs::path const& file, std::pair<const char *, size_t> default_config, const OptionSetting setting)
: config_file(file)
, setting(setting)
{
LOG_D("agi/options") << "New Options object";
boost::interprocess::ibufferstream stream(default_config.data(), default_config.size());
boost::interprocess::ibufferstream stream(default_config.first, default_config.second);
LoadConfig(stream);
}

View File

@ -99,7 +99,7 @@ public:
/// Constructor
/// @param file Location of user config file.
/// @param default_config Default config.
Hotkey(agi::fs::path const& file, const std::string &default_config);
Hotkey(agi::fs::path const& file, std::pair<const char *, size_t> default_config);
/// Scan for a matching key.
/// @param context Context requested.

View File

@ -39,7 +39,7 @@ json::UnknownElement file(agi::fs::path const& file);
/// @param file Path to JSON file.
/// @param Default config file to load incase of nonexistent file
/// @return json::UnknownElement
json::UnknownElement file(agi::fs::path const& file, const std::string &default_config);
json::UnknownElement file(agi::fs::path const& file, std::pair<const char *, size_t> default_config);
} // namespace json_util
} // namespace agi

View File

@ -54,7 +54,7 @@ public:
/// @brief Constructor
/// @param config File to load MRU values from
MRUManager(agi::fs::path const& config, std::string const& default_config, agi::Options *options = nullptr);
MRUManager(agi::fs::path const& config, std::pair<const char *, size_t> default_config, agi::Options *options = nullptr);
/// Destructor
~MRUManager();

View File

@ -74,7 +74,7 @@ public:
/// @brief Constructor
/// @param file User config that will be loaded from and written back to.
/// @param default_config Default configuration.
Options(agi::fs::path const& file, const std::string &default_config, const OptionSetting setting=NONE);
Options(agi::fs::path const& file, std::pair<const char *, size_t> default_config, const OptionSetting setting = NONE);
/// Destructor
~Options();

View File

@ -16,6 +16,11 @@
#include "libresrc.h"
#include <wx/bitmap.h>
#include <wx/icon.h>
#include <wx/image.h>
#include <wx/mstream.h>
wxBitmap libresrc_getimage(const unsigned char *buff, size_t size) {
wxMemoryInputStream mem(buff, size);
return wxBitmap(wxImage(mem));
@ -27,7 +32,3 @@ wxIcon libresrc_geticon(const unsigned char *buff, size_t size) {
icon.CopyFromBitmap(wxBitmap(wxImage(mem)));
return icon;
}
const std::string libresrc_getconfig(const unsigned char *config, size_t size) {
return std::string(reinterpret_cast<const char *>(config), size);
}

View File

@ -12,20 +12,17 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string>
#include <wx/bitmap.h>
#include <wx/icon.h>
#include <wx/image.h>
#include <wx/mstream.h>
#include <utility>
#include "bitmap.h"
#include "default_config.h"
class wxBitmap;
class wxIcon;
wxBitmap libresrc_getimage(const unsigned char *image, size_t size);
wxIcon libresrc_geticon(const unsigned char *image, size_t size);
#define GETIMAGE(a) libresrc_getimage(a, sizeof(a))
#define GETICON(a) libresrc_geticon(a, sizeof(a))
const std::string libresrc_getconfig(const unsigned char *config, size_t size);
#define GET_DEFAULT_CONFIG(a) libresrc_getconfig(a, sizeof(a))
#define GET_DEFAULT_CONFIG(a) std::make_pair(reinterpret_cast<const char *>(a), sizeof(a))