|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
e6d9f6 |
#include <qdir></qdir>
|
|
Toshihiro Shimizu |
890ddd |
#include <qsettings></qsettings>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO_MACOSX
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "macofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Imposto l'offlineGL usando AGL (per togliere la dipendenza da X)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TOfflineGL::Imp *MacOfflineGenerator1(const TDimension &dim) {
|
|
Shinya Kitaoka |
120a6e |
return new MacImplementation(dim);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <map></map>
|
|
tomosu |
eea0ac |
#include <sstream></sstream>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace TEnv;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// root dir
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class EnvGlobals { // singleton
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string m_applicationName;
|
|
Shinya Kitaoka |
120a6e |
std::string m_applicationVersion;
|
|
Shinya Kitaoka |
120a6e |
std::string m_applicationVersionWithoutRevision;
|
|
Shinya Kitaoka |
120a6e |
std::string m_applicationFullName;
|
|
Shinya Kitaoka |
120a6e |
std::string m_moduleName;
|
|
Shinya Kitaoka |
120a6e |
std::string m_rootVarName;
|
|
Shinya Kitaoka |
120a6e |
std::string m_systemVarPrefix;
|
|
Jeremy Bullock |
46512f |
std::string m_workingDirectory;
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_registryRoot;
|
|
Shinya Kitaoka |
120a6e |
TFilePath m_envFile;
|
|
Shinya Kitaoka |
120a6e |
TFilePath *m_stuffDir;
|
|
Shinya Kitaoka |
120a6e |
TFilePath *m_dllRelativeDir;
|
|
Jeremy Bullock |
46512f |
bool m_isPortable = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
acd6b8 |
EnvGlobals() : m_stuffDir(0) { setWorkingDirectory(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
~EnvGlobals() { delete m_stuffDir; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
static EnvGlobals *instance() {
|
|
Shinya Kitaoka |
120a6e |
static EnvGlobals _instance;
|
|
Shinya Kitaoka |
120a6e |
return &_instance;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath getSystemVarPath(std::string varName) {
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
return m_registryRoot + varName;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
QString settingsPath;
|
|
Campbell Barton |
e6d9f6 |
|
|
Campbell Barton |
e6d9f6 |
#ifdef MACOSX
|
|
Shinya Kitaoka |
120a6e |
settingsPath =
|
|
Shinya Kitaoka |
120a6e |
QString::fromStdString(getApplicationName()) + QString("_") +
|
|
Shinya Kitaoka |
120a6e |
QString::fromStdString(getApplicationVersionWithoutRevision()) +
|
|
Shinya Kitaoka |
120a6e |
QString(".app") + QString("/Contents/Resources/SystemVar.ini");
|
|
Shinya Kitaoka |
120a6e |
#else /* Generic Unix */
|
|
Shinya Kitaoka |
120a6e |
// TODO: use QStandardPaths::ConfigLocation when we drop Qt4
|
|
Shinya Kitaoka |
120a6e |
settingsPath = QDir::homePath();
|
|
Shinya Kitaoka |
120a6e |
settingsPath.append("/.config/");
|
|
Shinya Kitaoka |
120a6e |
settingsPath.append(getApplicationName().c_str());
|
|
Shinya Kitaoka |
120a6e |
settingsPath.append("/SystemVar.ini");
|
|
Campbell Barton |
e6d9f6 |
#endif
|
|
Campbell Barton |
e6d9f6 |
|
|
Shinya Kitaoka |
120a6e |
QSettings settings(settingsPath, QSettings::IniFormat);
|
|
Shinya Kitaoka |
120a6e |
QString qStr = QString::fromStdString(varName);
|
|
Shinya Kitaoka |
120a6e |
QString systemVar = settings.value(qStr).toString();
|
|
Shinya Kitaoka |
120a6e |
// printf("getSystemVarPath: path:%s key:%s var:%s\n",
|
|
Shinya Kitaoka |
120a6e |
// settingsPath.toStdString().data(), varName.data(),
|
|
Shinya Kitaoka |
120a6e |
// systemVar.toStdString().data());
|
|
Shinya Kitaoka |
120a6e |
return TFilePath(systemVar.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath getRootVarPath() { return getSystemVarPath(m_rootVarName); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string getSystemVarValue(std::string varName) {
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
return TSystem::getSystemValue(getSystemVarPath(varName)).toStdString();
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
TFilePath systemVarPath = getSystemVarPath(varName);
|
|
Shinya Kitaoka |
120a6e |
if (systemVarPath.isEmpty()) {
|
|
Shinya Kitaoka |
120a6e |
std::cout << "varName:" << varName << " TOONZROOT not set..."
|
|
Shinya Kitaoka |
120a6e |
<< std::endl;
|
|
Shinya Kitaoka |
120a6e |
return "";
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return ::to_string(systemVarPath);
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Shinya Kitaoka |
120a6e |
char *value = getenv(varName.c_str());
|
|
Shinya Kitaoka |
120a6e |
if (!value)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
std::cout << varName << " not set, returning
|
|
Shinya Kitaoka |
120a6e |
TOONZROOT" << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
//value = getenv("TOONZROOT");
|
|
Toshihiro Shimizu |
890ddd |
value="";
|
|
Toshihiro Shimizu |
890ddd |
std::cout << "!!!value= "<< value << std::endl;
|
|
Shinya Kitaoka |
120a6e |
if (!value)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
std::cout << varName << "TOONZROOT not
|
|
Shinya Kitaoka |
120a6e |
set..." << std::endl;
|
|
Shinya Kitaoka |
120a6e |
//exit(-1);
|
|
Shinya Kitaoka |
120a6e |
return "";
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
return string(value);
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TFilePath getStuffDir() {
|
|
Shinya Kitaoka |
120a6e |
if (m_stuffDir) return *m_stuffDir;
|
|
Jeremy Bullock |
46512f |
if (m_isPortable)
|
|
Jeremy Bullock |
46512f |
return TFilePath((getWorkingDirectory() + "\\portablestuff\\"));
|
|
Jeremy Bullock |
46512f |
|
|
Shinya Kitaoka |
120a6e |
return TFilePath(getSystemVarValue(m_rootVarName));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void setStuffDir(const TFilePath &stuffDir) {
|
|
Shinya Kitaoka |
120a6e |
delete m_stuffDir;
|
|
Shinya Kitaoka |
120a6e |
m_stuffDir = new TFilePath(stuffDir);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void updateEnvFile() {
|
|
Shinya Kitaoka |
120a6e |
TFilePath profilesDir =
|
|
Shinya Kitaoka |
120a6e |
getSystemVarPathValue(getSystemVarPrefix() + "PROFILES");
|
|
Shinya Kitaoka |
120a6e |
if (profilesDir == TFilePath()) profilesDir = getStuffDir() + "profiles";
|
|
Shinya Kitaoka |
120a6e |
m_envFile =
|
|
Shinya Kitaoka |
120a6e |
profilesDir + "env" + (TSystem::getUserName().toStdString() + ".env");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setApplication(std::string applicationName,
|
|
Shinya Kitaoka |
120a6e |
std::string applicationVersion, std::string revision) {
|
|
Shinya Kitaoka |
120a6e |
m_applicationName = applicationName;
|
|
Shinya Kitaoka |
120a6e |
m_applicationVersionWithoutRevision = applicationVersion;
|
|
Shinya Kitaoka |
120a6e |
if (!revision.empty()) {
|
|
Shinya Kitaoka |
120a6e |
m_applicationVersion =
|
|
Shinya Kitaoka |
120a6e |
m_applicationVersionWithoutRevision + "." + revision;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_applicationVersion = m_applicationVersionWithoutRevision;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_applicationFullName = m_applicationName + " " + m_applicationVersion;
|
|
Shinya Kitaoka |
120a6e |
m_moduleName = m_applicationName;
|
|
Shinya Kitaoka |
120a6e |
m_rootVarName = toUpper(m_applicationName) + "ROOT";
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
m_registryRoot = TFilePath("SOFTWARE\\OpenToonz\\") + m_applicationName +
|
|
Shinya Kitaoka |
120a6e |
applicationVersion;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
m_systemVarPrefix = m_applicationName;
|
|
Shinya Kitaoka |
120a6e |
updateEnvFile();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::string getApplicationName() { return m_applicationName; }
|
|
Shinya Kitaoka |
120a6e |
std::string getApplicationVersion() { return m_applicationVersion; }
|
|
Shinya Kitaoka |
120a6e |
std::string getApplicationVersionWithoutRevision() {
|
|
Shinya Kitaoka |
120a6e |
return m_applicationVersionWithoutRevision;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TFilePath getEnvFile() { return m_envFile; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setApplicationFullName(std::string applicationFullName) {
|
|
Shinya Kitaoka |
120a6e |
m_applicationFullName = applicationFullName;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
std::string getApplicationFullName() { return m_applicationFullName; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setModuleName(std::string moduleName) { m_moduleName = moduleName; }
|
|
Shinya Kitaoka |
120a6e |
std::string getModuleName() { return m_moduleName; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setRootVarName(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
m_rootVarName = varName;
|
|
Shinya Kitaoka |
120a6e |
updateEnvFile();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
std::string getRootVarName() { return m_rootVarName; }
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
acd6b8 |
void setSystemVarPrefix(std::string prefix) {
|
|
shun-iwasawa |
acd6b8 |
m_systemVarPrefix = prefix;
|
|
shun-iwasawa |
acd6b8 |
updateEnvFile();
|
|
shun-iwasawa |
acd6b8 |
}
|
|
Jeremy Bullock |
46512f |
std::string getSystemVarPrefix() {
|
|
Jeremy Bullock |
46512f |
if (getIsPortable()) return "";
|
|
Jeremy Bullock |
46512f |
return m_systemVarPrefix;
|
|
Jeremy Bullock |
46512f |
}
|
|
Jeremy Bullock |
46512f |
|
|
Jeremy Bullock |
46512f |
void setWorkingDirectory() {
|
|
Jeremy Bullock |
46512f |
QString workingDirectoryTmp = QDir::currentPath();
|
|
Jeremy Bullock |
46512f |
QByteArray ba = workingDirectoryTmp.toLatin1();
|
|
Jeremy Bullock |
46512f |
const char *workingDirectory = ba.data();
|
|
Jeremy Bullock |
46512f |
m_workingDirectory = workingDirectory;
|
|
Jeremy Bullock |
46512f |
|
|
Jeremy Bullock |
46512f |
// check if portable
|
|
Jeremy Bullock |
46512f |
TFilePath portableCheck =
|
|
Jeremy Bullock |
46512f |
TFilePath(m_workingDirectory + "\\portablestuff\\");
|
|
Jeremy Bullock |
46512f |
TFileStatus portableStatus(portableCheck);
|
|
Jeremy Bullock |
46512f |
m_isPortable = portableStatus.doesExist();
|
|
Jeremy Bullock |
46512f |
}
|
|
Jeremy Bullock |
46512f |
std::string getWorkingDirectory() { return m_workingDirectory; }
|
|
Jeremy Bullock |
46512f |
|
|
Jeremy Bullock |
46512f |
bool getIsPortable() { return m_isPortable; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setDllRelativeDir(const TFilePath &dllRelativeDir) {
|
|
Shinya Kitaoka |
120a6e |
delete m_dllRelativeDir;
|
|
Shinya Kitaoka |
120a6e |
m_dllRelativeDir = new TFilePath(dllRelativeDir);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TFilePath getDllRelativeDir() {
|
|
Shinya Kitaoka |
120a6e |
if (m_dllRelativeDir) return *m_dllRelativeDir;
|
|
Shinya Kitaoka |
120a6e |
return TFilePath(".");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
TFilePath EnvGlobals::getSystemPath(int id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, tfilepath="">::iterator it = m_systemPaths.find(id);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if(it != m_systemPaths.end()) return it->second;
|
|
Toshihiro Shimizu |
890ddd |
switch(id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
tomosu |
eea0ac |
case StuffDir: return TFilePath();
|
|
Toshihiro Shimizu |
890ddd |
case ConfigDir: return getSystemPath(StuffDir) + "config";
|
|
Toshihiro Shimizu |
890ddd |
case ProfilesDir: return getSystemPath(StuffDir) + "profiles";
|
|
tomosu |
eea0ac |
default: return TFilePath();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void EnvGlobals::setSystemPath(int id, const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_systemPaths[id] = fp;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Variable::Imp
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class Variable::Imp {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
std::string m_name;
|
|
Shinya Kitaoka |
120a6e |
std::string m_value;
|
|
Shinya Kitaoka |
120a6e |
bool m_loaded, m_defaultDefined, m_assigned;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Imp(std::string name)
|
|
Shinya Kitaoka |
120a6e |
: m_name(name)
|
|
Shinya Kitaoka |
120a6e |
, m_value("")
|
|
Shinya Kitaoka |
120a6e |
, m_loaded(false)
|
|
Shinya Kitaoka |
120a6e |
, m_defaultDefined(false)
|
|
Shinya Kitaoka |
120a6e |
, m_assigned(false) {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// varaible manager (singleton)
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class VariableSet {
|
|
Shinya Kitaoka |
120a6e |
std::map<std::string, *="" variable::imp=""> m_variables;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
bool m_loaded;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
VariableSet() : m_loaded(false) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~VariableSet() {
|
|
Shinya Kitaoka |
120a6e |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_variables.begin(); it != m_variables.end(); ++it)
|
|
Shinya Kitaoka |
120a6e |
delete it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
static VariableSet *instance() {
|
|
Shinya Kitaoka |
120a6e |
static VariableSet instance;
|
|
Shinya Kitaoka |
120a6e |
return &instance;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Variable::Imp *getImp(std::string name) {
|
|
Shinya Kitaoka |
120a6e |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
it = m_variables.find(name);
|
|
Shinya Kitaoka |
120a6e |
if (it == m_variables.end()) {
|
|
Shinya Kitaoka |
120a6e |
Variable::Imp *imp = new Variable::Imp(name);
|
|
Shinya Kitaoka |
120a6e |
m_variables[name] = imp;
|
|
Shinya Kitaoka |
120a6e |
return imp;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
return it->second;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void commit() {
|
|
Shinya Kitaoka |
120a6e |
// save();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void loadIfNeeded() {
|
|
Shinya Kitaoka |
120a6e |
if (m_loaded) return;
|
|
Shinya Kitaoka |
120a6e |
m_loaded = true;
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
load();
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void load();
|
|
Shinya Kitaoka |
120a6e |
void save();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void VariableSet::load() {
|
|
Campbell Barton |
e6d9f6 |
#ifndef WIN32
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->updateEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
TFilePath fp = EnvGlobals::instance()->getEnvFile();
|
|
Shinya Kitaoka |
120a6e |
if (fp == TFilePath()) return;
|
|
Shinya Kitaoka |
120a6e |
Tifstream is(fp);
|
|
Shinya Kitaoka |
120a6e |
if (!is) return;
|
|
Shinya Kitaoka |
120a6e |
char buffer[1024];
|
|
Shinya Kitaoka |
120a6e |
while (is.getline(buffer, sizeof(buffer))) {
|
|
Shinya Kitaoka |
120a6e |
char *s = buffer;
|
|
Shinya Kitaoka |
120a6e |
while (*s == ' ') s++;
|
|
Shinya Kitaoka |
120a6e |
char *t = s;
|
|
Shinya Kitaoka |
120a6e |
while ('a' <= *s && *s <= 'z' || 'A' <= *s && *s <= 'Z' ||
|
|
Shinya Kitaoka |
120a6e |
'0' <= *s && *s <= '9' || *s == '_')
|
|
Shinya Kitaoka |
120a6e |
s++;
|
|
Shinya Kitaoka |
120a6e |
std::string name(t, s - t);
|
|
Shinya Kitaoka |
120a6e |
if (name.size() == 0) continue;
|
|
Shinya Kitaoka |
120a6e |
while (*s == ' ') s++;
|
|
Shinya Kitaoka |
120a6e |
if (*s != '\"') continue;
|
|
Shinya Kitaoka |
120a6e |
s++;
|
|
Shinya Kitaoka |
120a6e |
std::string value;
|
|
Shinya Kitaoka |
120a6e |
while (*s != '\n' && *s != '\0' && *s != '\"') {
|
|
Shinya Kitaoka |
120a6e |
if (*s != '\\')
|
|
Shinya Kitaoka |
120a6e |
value.push_back(*s);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
s++;
|
|
Shinya Kitaoka |
120a6e |
if (*s == '\\')
|
|
Shinya Kitaoka |
120a6e |
value.push_back('\\');
|
|
Shinya Kitaoka |
120a6e |
else if (*s == '"')
|
|
Shinya Kitaoka |
120a6e |
value.push_back('"');
|
|
Shinya Kitaoka |
120a6e |
else if (*s == 'n')
|
|
Shinya Kitaoka |
120a6e |
value.push_back('\n');
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
s++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Variable::Imp *imp = getImp(name);
|
|
Shinya Kitaoka |
120a6e |
imp->m_value = value;
|
|
Shinya Kitaoka |
120a6e |
imp->m_loaded = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void VariableSet::save() {
|
|
Shinya Kitaoka |
120a6e |
TFilePath fp = EnvGlobals::instance()->getEnvFile();
|
|
Shinya Kitaoka |
120a6e |
if (fp == TFilePath()) return;
|
|
Shinya Kitaoka |
120a6e |
bool exists = TFileStatus(fp.getParentDir()).doesExist();
|
|
Shinya Kitaoka |
120a6e |
if (!exists) {
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
TSystem::mkDir(fp.getParentDir());
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Tofstream os(fp);
|
|
Shinya Kitaoka |
120a6e |
if (!os) return;
|
|
Shinya Kitaoka |
120a6e |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_variables.begin(); it != m_variables.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
os << it->first << " \"";
|
|
Shinya Kitaoka |
120a6e |
std::string s = it->second->m_value;
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)s.size(); i++)
|
|
Shinya Kitaoka |
120a6e |
if (s[i] == '\"')
|
|
Shinya Kitaoka |
120a6e |
os << "\\\"";
|
|
Shinya Kitaoka |
120a6e |
else if (s[i] == '\\')
|
|
Shinya Kitaoka |
120a6e |
os << "\\\\";
|
|
Shinya Kitaoka |
120a6e |
else if (s[i] == '\n')
|
|
Shinya Kitaoka |
120a6e |
os << "\\n";
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
os.put(s[i]);
|
|
Shinya Kitaoka |
120a6e |
os << "\"" << std::endl;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Variable::Variable(std::string name)
|
|
Shinya Kitaoka |
120a6e |
: m_imp(VariableSet::instance()->getImp(name)) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Variable::Variable(std::string name, std::string defaultValue)
|
|
Shinya Kitaoka |
120a6e |
: m_imp(VariableSet::instance()->getImp(name)) {
|
|
Shinya Kitaoka |
120a6e |
// assert(!m_imp->m_defaultDefined);
|
|
Shinya Kitaoka |
120a6e |
m_imp->m_defaultDefined = true;
|
|
Shinya Kitaoka |
120a6e |
if (!m_imp->m_loaded) m_imp->m_value = defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Variable::~Variable() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string Variable::getName() const { return m_imp->m_name; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string Variable::getValue() const {
|
|
Shinya Kitaoka |
120a6e |
VariableSet::instance()->loadIfNeeded();
|
|
Shinya Kitaoka |
120a6e |
return m_imp->m_value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void Variable::assignValue(std::string value) {
|
|
Shinya Kitaoka |
120a6e |
VariableSet *vs = VariableSet::instance();
|
|
Shinya Kitaoka |
120a6e |
vs->loadIfNeeded();
|
|
Shinya Kitaoka |
120a6e |
m_imp->m_value = value;
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
vs->commit();
|
|
Shinya Kitaoka |
120a6e |
} catch (...) {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setApplication(std::string applicationName,
|
|
Shinya Kitaoka |
120a6e |
std::string applicationVersion,
|
|
Shinya Kitaoka |
120a6e |
std::string revision) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setApplication(applicationName, applicationVersion,
|
|
Shinya Kitaoka |
120a6e |
revision);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO_MACOSX
|
|
Shinya Kitaoka |
120a6e |
TOfflineGL::defineImpGenerator(MacOfflineGenerator1);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getApplicationName() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getApplicationName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getApplicationVersion() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getApplicationVersion();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setApplicationFullName(std::string applicationFullName) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setApplicationFullName(applicationFullName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getApplicationFullName() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getApplicationFullName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setModuleName(std::string moduleName) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setModuleName(moduleName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getModuleName() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getModuleName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setRootVarName(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setRootVarName(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getRootVarName() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getRootVarName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath TEnv::getRootVarPath() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getRootVarPath();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getSystemVarStringValue(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getSystemVarValue(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath TEnv::getSystemVarPathValue(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals *eg = EnvGlobals::instance();
|
|
Shinya Kitaoka |
120a6e |
return TFilePath(eg->getSystemVarValue(varName));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePathSet TEnv::getSystemVarPathSetValue(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
TFilePathSet lst;
|
|
Shinya Kitaoka |
120a6e |
std::string value = EnvGlobals::instance()->getSystemVarValue(varName);
|
|
Shinya Kitaoka |
120a6e |
int len = (int)value.size();
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
int j = value.find(';');
|
|
Shinya Kitaoka |
120a6e |
while (j != std::string::npos) {
|
|
Shinya Kitaoka |
120a6e |
std::string s = value.substr(i, j - i);
|
|
Shinya Kitaoka |
120a6e |
lst.push_back(TFilePath(s));
|
|
Shinya Kitaoka |
120a6e |
i = j + 1;
|
|
Shinya Kitaoka |
120a6e |
if (i >= len) return lst;
|
|
Shinya Kitaoka |
120a6e |
j = value.find(';', i);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (i < len) lst.push_back(TFilePath(value.substr(i)));
|
|
Shinya Kitaoka |
120a6e |
return lst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setSystemVarPrefix(std::string varName) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setSystemVarPrefix(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::string TEnv::getSystemVarPrefix() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getSystemVarPrefix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath TEnv::getStuffDir() {
|
|
Shinya Kitaoka |
120a6e |
//#ifdef MACOSX
|
|
Shinya Kitaoka |
120a6e |
// return TFilePath("/Applications/Toonz 5.0/Toonz 5.0 stuff");
|
|
Shinya Kitaoka |
120a6e |
//#else
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getStuffDir();
|
|
Shinya Kitaoka |
120a6e |
//#endif
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
46512f |
bool TEnv::getIsPortable() { return EnvGlobals::instance()->getIsPortable(); }
|
|
Jeremy Bullock |
46512f |
|
|
Shinya Kitaoka |
120a6e |
TFilePath TEnv::getConfigDir() {
|
|
Shinya Kitaoka |
120a6e |
TFilePath configDir = getSystemVarPathValue(getSystemVarPrefix() + "CONFIG");
|
|
Shinya Kitaoka |
120a6e |
if (configDir == TFilePath()) configDir = getStuffDir() + "config";
|
|
Shinya Kitaoka |
120a6e |
return configDir;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*TFilePath TEnv::getProfilesDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp(getStuffDir());
|
|
Toshihiro Shimizu |
890ddd |
return fp != TFilePath() ? fp + "profiles" : fp;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setStuffDir(const TFilePath &stuffDir) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setStuffDir(stuffDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFilePath TEnv::getDllRelativeDir() {
|
|
Shinya Kitaoka |
120a6e |
return EnvGlobals::instance()->getDllRelativeDir();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::setDllRelativeDir(const TFilePath &dllRelativeDir) {
|
|
Shinya Kitaoka |
120a6e |
EnvGlobals::instance()->setDllRelativeDir(dllRelativeDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TEnv::saveAllEnvVariables() { VariableSet::instance()->save(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void TEnv::defineSystemPath(SystemFileId id, const TFilePath ®istryName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
string s = TSystem::getSystemValue(registryName);
|
|
Toshihiro Shimizu |
890ddd |
if(s=="") return;
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setSystemPath(id, TFilePath(s));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TEnv::getSystemPath(SystemFileId id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getSystemPath(id);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Variabili tipizzate
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::istream &operator>>(std::istream &is, TFilePath &path) {
|
|
Shinya Kitaoka |
120a6e |
std::string s;
|
|
Shinya Kitaoka |
120a6e |
is >> s;
|
|
Shinya Kitaoka |
120a6e |
return is;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::istream &operator>>(std::istream &is, TRect &rect) {
|
|
Shinya Kitaoka |
120a6e |
return is >> rect.x0 >> rect.y0 >> rect.x1 >> rect.y1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
std::string toString2(T value) {
|
|
Shinya Kitaoka |
120a6e |
std::ostringstream ss;
|
|
Shinya Kitaoka |
120a6e |
ss << value << '\0';
|
|
Shinya Kitaoka |
120a6e |
return ss.str();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
120a6e |
std::string toString2(TRect value) {
|
|
Shinya Kitaoka |
120a6e |
std::ostringstream ss;
|
|
Shinya Kitaoka |
120a6e |
ss << value.x0 << " " << value.y0 << " " << value.x1 << " " << value.y1
|
|
Shinya Kitaoka |
120a6e |
<< '\0';
|
|
Shinya Kitaoka |
120a6e |
return ss.str();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
void fromString(std::string s, T &value) {
|
|
Shinya Kitaoka |
120a6e |
if (s.empty()) return;
|
|
Shinya Kitaoka |
120a6e |
std::istringstream is(s);
|
|
Shinya Kitaoka |
120a6e |
is >> value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void fromString(std::string s, std::string &value) { value = s; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
IntVar::IntVar(std::string name, int defValue)
|
|
Shinya Kitaoka |
120a6e |
: Variable(name, std::to_string(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
IntVar::IntVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
120a6e |
IntVar::operator int() const {
|
|
Shinya Kitaoka |
120a6e |
int v;
|
|
Shinya Kitaoka |
120a6e |
fromString(getValue(), v);
|
|
Shinya Kitaoka |
120a6e |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
9eb50d |
void IntVar::operator=(int v) { assignValue(std::to_string(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DoubleVar::DoubleVar(std::string name, double defValue)
|
|
Shinya Kitaoka |
120a6e |
: Variable(name, std::to_string(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
DoubleVar::DoubleVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
120a6e |
DoubleVar::operator double() const {
|
|
Shinya Kitaoka |
120a6e |
double v;
|
|
Shinya Kitaoka |
120a6e |
fromString(getValue(), v);
|
|
Shinya Kitaoka |
120a6e |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
9eb50d |
void DoubleVar::operator=(double v) { assignValue(std::to_string(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
StringVar::StringVar(std::string name, const std::string &defValue)
|
|
Shinya Kitaoka |
120a6e |
: Variable(name, defValue) {}
|
|
Shinya Kitaoka |
3bfa54 |
StringVar::StringVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
120a6e |
StringVar::operator std::string() const {
|
|
Shinya Kitaoka |
120a6e |
std::string v;
|
|
Shinya Kitaoka |
120a6e |
fromString(getValue(), v);
|
|
Shinya Kitaoka |
120a6e |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
3bfa54 |
void StringVar::operator=(const std::string &v) { assignValue(v); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
FilePathVar::FilePathVar(std::string name, const TFilePath &defValue)
|
|
Shinya Kitaoka |
120a6e |
: Variable(name, ::to_string(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
FilePathVar::FilePathVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
120a6e |
FilePathVar::operator TFilePath() const {
|
|
Shinya Kitaoka |
120a6e |
std::string v;
|
|
Shinya Kitaoka |
120a6e |
fromString(getValue(), v);
|
|
Shinya Kitaoka |
120a6e |
return TFilePath(v);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
9eb50d |
void FilePathVar::operator=(const TFilePath &v) { assignValue(::to_string(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
RectVar::RectVar(std::string name, const TRect &defValue)
|
|
Shinya Kitaoka |
120a6e |
: Variable(name, toString2(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
RectVar::RectVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
120a6e |
RectVar::operator TRect() const {
|
|
Shinya Kitaoka |
120a6e |
TRect v;
|
|
Shinya Kitaoka |
120a6e |
fromString(getValue(), v);
|
|
Shinya Kitaoka |
120a6e |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void RectVar::operator=(const TRect &v) { assignValue(toString2(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|