|
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 |
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
TOfflineGL::Imp *MacOfflineGenerator1(const TDimension &dim)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return new MacImplementation(dim);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include <typeinfo></typeinfo>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include <ctype.h></ctype.h>
|
|
Toshihiro Shimizu |
890ddd |
//#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <map></map>
|
|
Toshihiro Shimizu |
890ddd |
//#include <fstream.h></fstream.h>
|
|
Toshihiro Shimizu |
890ddd |
//#include <strstream.h></strstream.h>
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class EnvGlobals
|
|
Toshihiro Shimizu |
890ddd |
{ // singleton
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_applicationName;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_applicationVersion;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_applicationFullName;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_moduleName;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_rootVarName;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_systemVarPrefix;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath m_registryRoot;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath m_envFile;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath *m_stuffDir;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath *m_dllRelativeDir;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals() : m_stuffDir(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
~EnvGlobals() { delete m_stuffDir; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static EnvGlobals *instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static EnvGlobals _instance;
|
|
Toshihiro Shimizu |
890ddd |
return &_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TFilePath getSystemVarPath(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
return m_registryRoot + varName;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
QString settingsPath = QString::fromStdString(getApplicationName()) + QString("_") +
|
|
Toshihiro Shimizu |
890ddd |
QString::fromStdString(getApplicationVersion()) + QString(".app") +
|
|
Toshihiro Shimizu |
890ddd |
QString("/Contents/Resources/SystemVar.ini");
|
|
Toshihiro Shimizu |
890ddd |
QSettings settings(settingsPath, QSettings::IniFormat);
|
|
Toshihiro Shimizu |
890ddd |
QString qStr = QString::fromStdString(varName);
|
|
Toshihiro Shimizu |
890ddd |
QString systemVar = settings.value(qStr).toString();
|
|
Toshihiro Shimizu |
890ddd |
//printf("getSystemVarPath: path:%s key:%s var:%s\n", settingsPath.toStdString().data(), varName.data(), systemVar.toStdString().data());
|
|
Toshihiro Shimizu |
890ddd |
return TFilePath(systemVar.toStdWString());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath getRootVarPath()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return getSystemVarPath(m_rootVarName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string getSystemVarValue(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
return TSystem::getSystemValue(getSystemVarPath(varName)).toStdString();
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
TFilePath systemVarPath = getSystemVarPath(varName);
|
|
Toshihiro Shimizu |
890ddd |
if (systemVarPath.isEmpty()) {
|
|
Toshihiro Shimizu |
890ddd |
std::cout << "varName:" << varName << " TOONZROOT not set..." << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
return "";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return toString(systemVarPath);
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
char *value = getenv(varName.c_str());
|
|
Toshihiro Shimizu |
890ddd |
if (!value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::cout << varName << " not set, returning TOONZROOT" << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
//value = getenv("TOONZROOT");
|
|
Toshihiro Shimizu |
890ddd |
value="";
|
|
Toshihiro Shimizu |
890ddd |
std::cout << "!!!value= "<< value << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
if (!value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::cout << varName << "TOONZROOT not set..." << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
//exit(-1);
|
|
Toshihiro Shimizu |
890ddd |
return "";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return string(value);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath getStuffDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_stuffDir)
|
|
Toshihiro Shimizu |
890ddd |
return *m_stuffDir;
|
|
Toshihiro Shimizu |
890ddd |
return TFilePath(getSystemVarValue(m_rootVarName));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void setStuffDir(const TFilePath &stuffDir)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_stuffDir;
|
|
Toshihiro Shimizu |
890ddd |
m_stuffDir = new TFilePath(stuffDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void updateEnvFile()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath profilesDir = getSystemVarPathValue(getSystemVarPrefix() + "PROFILES");
|
|
Toshihiro Shimizu |
890ddd |
if (profilesDir == TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
profilesDir = getStuffDir() + "profiles";
|
|
Toshihiro Shimizu |
890ddd |
m_envFile = profilesDir + "env" + (TSystem::getUserName().toStdString() + ".env");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setApplication(std::string applicationName, std::string applicationVersion)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_applicationName = applicationName;
|
|
Toshihiro Shimizu |
890ddd |
m_applicationVersion = applicationVersion;
|
|
Toshihiro Shimizu |
890ddd |
m_applicationFullName = m_applicationName + " " + m_applicationVersion;
|
|
Toshihiro Shimizu |
890ddd |
m_moduleName = m_applicationName;
|
|
Toshihiro Shimizu |
890ddd |
m_rootVarName = toUpper(m_applicationName) + "ROOT";
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
m_registryRoot = TFilePath("SOFTWARE\\OpenToonz\\") + m_applicationName + m_applicationVersion;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
m_systemVarPrefix = m_applicationName;
|
|
Toshihiro Shimizu |
890ddd |
updateEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string getApplicationName() { return m_applicationName; }
|
|
Shinya Kitaoka |
3bfa54 |
std::string getApplicationVersion() { return m_applicationVersion; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath getEnvFile() { return m_envFile; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setApplicationFullName(std::string applicationFullName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_applicationFullName = applicationFullName;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
3bfa54 |
std::string getApplicationFullName() { return m_applicationFullName; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setModuleName(std::string moduleName) { m_moduleName = moduleName; }
|
|
Shinya Kitaoka |
3bfa54 |
std::string getModuleName() { return m_moduleName; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setRootVarName(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_rootVarName = varName;
|
|
Toshihiro Shimizu |
890ddd |
updateEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
3bfa54 |
std::string getRootVarName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_rootVarName;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setSystemVarPrefix(std::string prefix)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_systemVarPrefix = prefix;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
3bfa54 |
std::string getSystemVarPrefix() { return m_systemVarPrefix; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setDllRelativeDir(const TFilePath &dllRelativeDir)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_dllRelativeDir;
|
|
Toshihiro Shimizu |
890ddd |
m_dllRelativeDir = new TFilePath(dllRelativeDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath getDllRelativeDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_dllRelativeDir)
|
|
Toshihiro Shimizu |
890ddd |
return *m_dllRelativeDir;
|
|
Toshihiro Shimizu |
890ddd |
return TFilePath(".");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
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 |
{
|
|
Toshihiro Shimizu |
890ddd |
case StuffDir: return TFilePath();
|
|
Toshihiro Shimizu |
890ddd |
case ConfigDir: return getSystemPath(StuffDir) + "config";
|
|
Toshihiro Shimizu |
890ddd |
case ProfilesDir: return getSystemPath(StuffDir) + "profiles";
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// Variable::Imp
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class Variable::Imp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_name;
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_value;
|
|
Toshihiro Shimizu |
890ddd |
bool m_loaded, m_defaultDefined, m_assigned;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Imp(std::string name)
|
|
Toshihiro Shimizu |
890ddd |
: m_name(name), m_value(""), m_loaded(false), m_defaultDefined(false), 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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class VariableSet
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::string, *="" variable::imp=""> m_variables;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
bool m_loaded;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
VariableSet() : m_loaded(false) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~VariableSet()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_variables.begin(); it != m_variables.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
delete it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static VariableSet *instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static VariableSet instance;
|
|
Toshihiro Shimizu |
890ddd |
return &instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Variable::Imp *getImp(std::string name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
it = m_variables.find(name);
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_variables.end()) {
|
|
Toshihiro Shimizu |
890ddd |
Variable::Imp *imp = new Variable::Imp(name);
|
|
Toshihiro Shimizu |
890ddd |
m_variables[name] = imp;
|
|
Toshihiro Shimizu |
890ddd |
return imp;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void commit()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//save();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void loadIfNeeded()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_loaded)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_loaded = true;
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
load();
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void load();
|
|
Toshihiro Shimizu |
890ddd |
void save();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void VariableSet::load()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#ifdef MACOSX
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->updateEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = EnvGlobals::instance()->getEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
if (fp == TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
Tifstream is(fp);
|
|
Toshihiro Shimizu |
890ddd |
if (!is)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
char buffer[1024];
|
|
Toshihiro Shimizu |
890ddd |
while (is.getline(buffer, sizeof(buffer))) {
|
|
Toshihiro Shimizu |
890ddd |
char *s = buffer;
|
|
Toshihiro Shimizu |
890ddd |
while (*s == ' ')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
char *t = s;
|
|
Toshihiro Shimizu |
890ddd |
while ('a' <= *s && *s <= 'z' || 'A' <= *s && *s <= 'Z' || '0' <= *s && *s <= '9' || *s == '_')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Shinya Kitaoka |
3bfa54 |
std::string name(t, s - t);
|
|
Toshihiro Shimizu |
890ddd |
if (name.size() == 0)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
while (*s == ' ')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s != '\"')
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Shinya Kitaoka |
3bfa54 |
std::string value;
|
|
Toshihiro Shimizu |
890ddd |
while (*s != '\n' && *s != '\0' && *s != '\"') {
|
|
Toshihiro Shimizu |
890ddd |
if (*s != '\\')
|
|
Toshihiro Shimizu |
890ddd |
value.push_back(*s);
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == '\\')
|
|
Toshihiro Shimizu |
890ddd |
value.push_back('\\');
|
|
Toshihiro Shimizu |
890ddd |
else if (*s == '"')
|
|
Toshihiro Shimizu |
890ddd |
value.push_back('"');
|
|
Toshihiro Shimizu |
890ddd |
else if (*s == 'n')
|
|
Toshihiro Shimizu |
890ddd |
value.push_back('\n');
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Variable::Imp *imp = getImp(name);
|
|
Toshihiro Shimizu |
890ddd |
imp->m_value = value;
|
|
Toshihiro Shimizu |
890ddd |
imp->m_loaded = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void VariableSet::save()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = EnvGlobals::instance()->getEnvFile();
|
|
Toshihiro Shimizu |
890ddd |
if (fp == TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
bool exists = TFileStatus(fp.getParentDir()).doesExist();
|
|
Toshihiro Shimizu |
890ddd |
if (!exists) {
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
TSystem::mkDir(fp.getParentDir());
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Tofstream os(fp);
|
|
Toshihiro Shimizu |
890ddd |
if (!os)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::string, *="" variable::imp="">::iterator it;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_variables.begin(); it != m_variables.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
os << it->first << " \"";
|
|
Shinya Kitaoka |
3bfa54 |
std::string s = it->second->m_value;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)s.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
if (s[i] == '\"')
|
|
Toshihiro Shimizu |
890ddd |
os << "\\\"";
|
|
Toshihiro Shimizu |
890ddd |
else if (s[i] == '\\')
|
|
Toshihiro Shimizu |
890ddd |
os << "\\\\";
|
|
Toshihiro Shimizu |
890ddd |
else if (s[i] == '\n')
|
|
Toshihiro Shimizu |
890ddd |
os << "\\n";
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
os.put(s[i]);
|
|
Toshihiro Shimizu |
890ddd |
os << "\"" << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Variable::Variable(std::string name)
|
|
Toshihiro Shimizu |
890ddd |
: m_imp(VariableSet::instance()->getImp(name))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Variable::Variable(std::string name, std::string defaultValue)
|
|
Toshihiro Shimizu |
890ddd |
: m_imp(VariableSet::instance()->getImp(name))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//assert(!m_imp->m_defaultDefined);
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_defaultDefined = true;
|
|
Toshihiro Shimizu |
890ddd |
if (!m_imp->m_loaded)
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_value = defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Variable::~Variable()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string Variable::getName() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->m_name;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string Variable::getValue() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VariableSet::instance()->loadIfNeeded();
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->m_value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void Variable::assignValue(std::string value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VariableSet *vs = VariableSet::instance();
|
|
Toshihiro Shimizu |
890ddd |
vs->loadIfNeeded();
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_value = value;
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
vs->commit();
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnv::setApplication(std::string applicationName, std::string applicationVersion)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setApplication(applicationName, applicationVersion);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef LEVO_MACOSX
|
|
Toshihiro Shimizu |
890ddd |
TOfflineGL::defineImpGenerator(MacOfflineGenerator1);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getApplicationName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getApplicationName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getApplicationVersion()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getApplicationVersion();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnv::setApplicationFullName(std::string applicationFullName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setApplicationFullName(applicationFullName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getApplicationFullName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getApplicationFullName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnv::setModuleName(std::string moduleName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setModuleName(moduleName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getModuleName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getModuleName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnv::setRootVarName(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setRootVarName(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getRootVarName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getRootVarName();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TEnv::getRootVarPath()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getRootVarPath();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getSystemVarStringValue(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getSystemVarValue(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TFilePath TEnv::getSystemVarPathValue(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals *eg = EnvGlobals::instance();
|
|
Toshihiro Shimizu |
890ddd |
return TFilePath(eg->getSystemVarValue(varName));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TFilePathSet TEnv::getSystemVarPathSetValue(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePathSet lst;
|
|
Shinya Kitaoka |
3bfa54 |
std::string value = EnvGlobals::instance()->getSystemVarValue(varName);
|
|
Toshihiro Shimizu |
890ddd |
int len = (int)value.size();
|
|
Toshihiro Shimizu |
890ddd |
int i = 0;
|
|
Toshihiro Shimizu |
890ddd |
int j = value.find(';');
|
|
Shinya Kitaoka |
3bfa54 |
while (j != std::string::npos) {
|
|
Shinya Kitaoka |
3bfa54 |
std::string s = value.substr(i, j - i);
|
|
Toshihiro Shimizu |
890ddd |
lst.push_back(TFilePath(s));
|
|
Toshihiro Shimizu |
890ddd |
i = j + 1;
|
|
Toshihiro Shimizu |
890ddd |
if (i >= len)
|
|
Toshihiro Shimizu |
890ddd |
return lst;
|
|
Toshihiro Shimizu |
890ddd |
j = value.find(';', i);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (i < len)
|
|
Toshihiro Shimizu |
890ddd |
lst.push_back(TFilePath(value.substr(i)));
|
|
Toshihiro Shimizu |
890ddd |
return lst;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnv::setSystemVarPrefix(std::string varName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setSystemVarPrefix(varName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string TEnv::getSystemVarPrefix()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getSystemVarPrefix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TEnv::getStuffDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//#ifdef MACOSX
|
|
Toshihiro Shimizu |
890ddd |
//return TFilePath("/Applications/Toonz 5.0/Toonz 5.0 stuff");
|
|
Toshihiro Shimizu |
890ddd |
//#else
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getStuffDir();
|
|
Toshihiro Shimizu |
890ddd |
//#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TEnv::getConfigDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath configDir = getSystemVarPathValue(getSystemVarPrefix() + "CONFIG");
|
|
Toshihiro Shimizu |
890ddd |
if (configDir == TFilePath())
|
|
Toshihiro Shimizu |
890ddd |
configDir = getStuffDir() + "config";
|
|
Toshihiro Shimizu |
890ddd |
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 |
*/
|
|
Toshihiro Shimizu |
890ddd |
void TEnv::setStuffDir(const TFilePath &stuffDir)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setStuffDir(stuffDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath TEnv::getDllRelativeDir()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnvGlobals::instance()->getDllRelativeDir();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnv::setDllRelativeDir(const TFilePath &dllRelativeDir)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
EnvGlobals::instance()->setDllRelativeDir(dllRelativeDir);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnv::saveAllEnvVariables()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
VariableSet::instance()->save();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::istream &operator>>(std::istream &is, TFilePath &path)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string s;
|
|
Toshihiro Shimizu |
890ddd |
is >> s;
|
|
Toshihiro Shimizu |
890ddd |
return is;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::istream &operator>>(std::istream &is, TRect &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
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 |
3bfa54 |
std::string toString2(T value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::ostrstream ss;
|
|
Toshihiro Shimizu |
890ddd |
ss << value << '\0';
|
|
Shinya Kitaoka |
3bfa54 |
std::string s(ss.str());
|
|
kogaki |
5bbc3c |
ss.freeze(false);
|
|
Toshihiro Shimizu |
890ddd |
return s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <>
|
|
Shinya Kitaoka |
3bfa54 |
std::string toString2(TRect value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::ostrstream ss;
|
|
Toshihiro Shimizu |
890ddd |
ss << value.x0 << " " << value.y0 << " " << value.x1 << " " << value.y1 << '\0';
|
|
Shinya Kitaoka |
3bfa54 |
std::string s = ss.str();
|
|
kogaki |
5bbc3c |
ss.freeze(false);
|
|
Toshihiro Shimizu |
890ddd |
return s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
3bfa54 |
void fromString(std::string s, T &value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (s.empty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Shinya Kitaoka |
3bfa54 |
std::istrstream is(s.c_str(), s.size());
|
|
Toshihiro Shimizu |
890ddd |
is >> value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void fromString(std::string s, std::string &value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
value = s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
IntVar::IntVar(std::string name, int defValue) : Variable(name, toString(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
IntVar::IntVar(std::string name) : Variable(name) {}
|
|
Toshihiro Shimizu |
890ddd |
IntVar::operator int() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int v;
|
|
Toshihiro Shimizu |
890ddd |
fromString(getValue(), v);
|
|
Toshihiro Shimizu |
890ddd |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void IntVar::operator=(int v) { assignValue(toString(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
DoubleVar::DoubleVar(std::string name, double defValue) : Variable(name, toString(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
DoubleVar::DoubleVar(std::string name) : Variable(name) {}
|
|
Toshihiro Shimizu |
890ddd |
DoubleVar::operator double() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double v;
|
|
Toshihiro Shimizu |
890ddd |
fromString(getValue(), v);
|
|
Toshihiro Shimizu |
890ddd |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void DoubleVar::operator=(double v) { assignValue(toString(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
StringVar::StringVar(std::string name, const std::string &defValue) : Variable(name, defValue) {}
|
|
Shinya Kitaoka |
3bfa54 |
StringVar::StringVar(std::string name) : Variable(name) {}
|
|
Shinya Kitaoka |
3bfa54 |
StringVar::operator std::string() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string v;
|
|
Toshihiro Shimizu |
890ddd |
fromString(getValue(), v);
|
|
Toshihiro Shimizu |
890ddd |
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 |
3bfa54 |
FilePathVar::FilePathVar(std::string name, const TFilePath &defValue) : Variable(name, toString(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
FilePathVar::FilePathVar(std::string name) : Variable(name) {}
|
|
Toshihiro Shimizu |
890ddd |
FilePathVar::operator TFilePath() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string v;
|
|
Toshihiro Shimizu |
890ddd |
fromString(getValue(), v);
|
|
Toshihiro Shimizu |
890ddd |
return TFilePath(v);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void FilePathVar::operator=(const TFilePath &v) { assignValue(toString(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
RectVar::RectVar(std::string name, const TRect &defValue) : Variable(name, toString2(defValue)) {}
|
|
Shinya Kitaoka |
3bfa54 |
RectVar::RectVar(std::string name) : Variable(name) {}
|
|
Toshihiro Shimizu |
890ddd |
RectVar::operator TRect() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRect v;
|
|
Toshihiro Shimizu |
890ddd |
fromString(getValue(), v);
|
|
Toshihiro Shimizu |
890ddd |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void RectVar::operator=(const TRect &v) { assignValue(toString2(v)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|