mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-05 18:40:37 +00:00
Add missing "cfg" library (fix #506)
This commit is contained in:
parent
63995c6f0a
commit
8f6cf34a78
4
src/cfg/CMakeLists.txt
Normal file
4
src/cfg/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Aseprite Config Library
|
||||||
|
# Copyright (c) 2014 David Capello
|
||||||
|
|
||||||
|
add_library(cfg-lib cfg.cpp)
|
20
src/cfg/LICENSE.txt
Normal file
20
src/cfg/LICENSE.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) 2014 David Capello
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4
src/cfg/README.md
Normal file
4
src/cfg/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Aseprite Config Library
|
||||||
|
*Copyright (C) 2014 David Capello*
|
||||||
|
|
||||||
|
> Distributed under [MIT license](LICENSE.txt)
|
148
src/cfg/cfg.cpp
Normal file
148
src/cfg/cfg.cpp
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// Aseprite Config Library
|
||||||
|
// Copyright (c) 2014 David Capello
|
||||||
|
//
|
||||||
|
// This file is released under the terms of the MIT license.
|
||||||
|
// Read LICENSE.txt for more information.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "cfg/cfg.h"
|
||||||
|
|
||||||
|
#include "base/file_handle.h"
|
||||||
|
#include "base/string.h"
|
||||||
|
|
||||||
|
#include "SimpleIni.h"
|
||||||
|
|
||||||
|
namespace cfg {
|
||||||
|
|
||||||
|
class CfgFile::CfgFileImpl {
|
||||||
|
public:
|
||||||
|
const std::string& filename() const {
|
||||||
|
return m_filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* getValue(const char* section, const char* name, const char* defaultValue) const {
|
||||||
|
return m_ini.GetValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getBoolValue(const char* section, const char* name, bool defaultValue) const {
|
||||||
|
return m_ini.GetBoolValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getIntValue(const char* section, const char* name, int defaultValue) const {
|
||||||
|
return m_ini.GetLongValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
double getDoubleValue(const char* section, const char* name, double defaultValue) const {
|
||||||
|
return m_ini.GetDoubleValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setValue(const char* section, const char* name, const char* value) {
|
||||||
|
m_ini.SetValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBoolValue(const char* section, const char* name, bool value) {
|
||||||
|
m_ini.SetBoolValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIntValue(const char* section, const char* name, int value) {
|
||||||
|
m_ini.SetLongValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDoubleValue(const char* section, const char* name, double value) {
|
||||||
|
m_ini.SetDoubleValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void load(const std::string& filename) {
|
||||||
|
m_filename = filename;
|
||||||
|
|
||||||
|
base::FileHandle file(base::open_file(m_filename, "rb"));
|
||||||
|
if (file) {
|
||||||
|
SI_Error err = m_ini.LoadFile(file.get());
|
||||||
|
if (err != SI_OK)
|
||||||
|
PRINTF("Error '%d' loading configuration from '%s'.", err, m_filename.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void save() {
|
||||||
|
base::FileHandle file(base::open_file(m_filename, "wb"));
|
||||||
|
if (file) {
|
||||||
|
SI_Error err = m_ini.SaveFile(file.get());
|
||||||
|
if (err != SI_OK)
|
||||||
|
PRINTF("Error '%d' saving configuration into '%s'.", err, m_filename.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_filename;
|
||||||
|
CSimpleIniA m_ini;
|
||||||
|
};
|
||||||
|
|
||||||
|
CfgFile::CfgFile()
|
||||||
|
: m_impl(new CfgFileImpl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CfgFile::~CfgFile()
|
||||||
|
{
|
||||||
|
delete m_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& CfgFile::filename() const
|
||||||
|
{
|
||||||
|
return m_impl->filename();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* CfgFile::getValue(const char* section, const char* name, const char* defaultValue) const
|
||||||
|
{
|
||||||
|
return m_impl->getValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CfgFile::getBoolValue(const char* section, const char* name, bool defaultValue)
|
||||||
|
{
|
||||||
|
return m_impl->getBoolValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CfgFile::getIntValue(const char* section, const char* name, int defaultValue)
|
||||||
|
{
|
||||||
|
return m_impl->getIntValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CfgFile::getDoubleValue(const char* section, const char* name, double defaultValue)
|
||||||
|
{
|
||||||
|
return m_impl->getDoubleValue(section, name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::setValue(const char* section, const char* name, const char* value)
|
||||||
|
{
|
||||||
|
m_impl->setValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::setBoolValue(const char* section, const char* name, bool value)
|
||||||
|
{
|
||||||
|
m_impl->setBoolValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::setIntValue(const char* section, const char* name, int value)
|
||||||
|
{
|
||||||
|
m_impl->setIntValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::setDoubleValue(const char* section, const char* name, double value)
|
||||||
|
{
|
||||||
|
m_impl->setDoubleValue(section, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::load(const std::string& filename)
|
||||||
|
{
|
||||||
|
m_impl->load(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CfgFile::save()
|
||||||
|
{
|
||||||
|
m_impl->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace cfg
|
42
src/cfg/cfg.h
Normal file
42
src/cfg/cfg.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Aseprite Config Library
|
||||||
|
// Copyright (c) 2014 David Capello
|
||||||
|
//
|
||||||
|
// This file is released under the terms of the MIT license.
|
||||||
|
// Read LICENSE.txt for more information.
|
||||||
|
|
||||||
|
#ifndef CFG_CFG_H_INCLUDED
|
||||||
|
#define CFG_CFG_H_INCLUDED
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace cfg {
|
||||||
|
|
||||||
|
class CfgFile {
|
||||||
|
public:
|
||||||
|
CfgFile();
|
||||||
|
~CfgFile();
|
||||||
|
|
||||||
|
const std::string& filename() const;
|
||||||
|
|
||||||
|
const char* getValue(const char* section, const char* name, const char* defaultValue) const;
|
||||||
|
bool getBoolValue(const char* section, const char* name, bool defaultValue);
|
||||||
|
int getIntValue(const char* section, const char* name, int defaultValue);
|
||||||
|
double getDoubleValue(const char* section, const char* name, double defaultValue);
|
||||||
|
|
||||||
|
void setValue(const char* section, const char* name, const char* value);
|
||||||
|
void setBoolValue(const char* section, const char* name, bool value);
|
||||||
|
void setIntValue(const char* section, const char* name, int value);
|
||||||
|
void setDoubleValue(const char* section, const char* name, double value);
|
||||||
|
|
||||||
|
void load(const std::string& filename);
|
||||||
|
void save();
|
||||||
|
|
||||||
|
private:
|
||||||
|
class CfgFileImpl;
|
||||||
|
CfgFileImpl* m_impl;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace cfg
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user