Skip to content

Commit

Permalink
explicit instead of using namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel committed Sep 27, 2017
1 parent d6df635 commit b65dea2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 114 deletions.
61 changes: 0 additions & 61 deletions OMShell/OMShellGUI/inputcelldelegate.h

This file was deleted.

4 changes: 1 addition & 3 deletions OMShell/OMShellGUI/omcinteractiveenvironment.cpp
Expand Up @@ -67,8 +67,6 @@ void omc_Main_setWindowsPaths(threadData_t *threadData, void* _inOMHome);
#endif
}

using namespace std;

namespace IAEX
{
OmcInteractiveEnvironment* OmcInteractiveEnvironment::selfInstance = NULL;
Expand Down Expand Up @@ -229,7 +227,7 @@ namespace IAEX
version.remove( "\"" );
//delete env;
}
catch( exception &e )
catch( std::exception &e )
{
e.what();
QMessageBox::critical( 0, QObject::tr("OMC Error"), QObject::tr("Unable to get OMC version, OMC is not started.") );
Expand Down
3 changes: 1 addition & 2 deletions OMShell/OMShellGUI/omcinteractiveenvironment.h
Expand Up @@ -36,12 +36,11 @@
#include <QtCore/QString>

#include "meta/meta_modelica.h"
#include "inputcelldelegate.h"
#include "omc_config.h"

namespace IAEX
{
class OmcInteractiveEnvironment : public InputCellDelegate
class OmcInteractiveEnvironment
{
private:
OmcInteractiveEnvironment();
Expand Down
1 change: 0 additions & 1 deletion OMShell/OMShellGUI/oms.h
Expand Up @@ -72,7 +72,6 @@ using namespace std;
#endif

//IAEX Headers
#include "inputcelldelegate.h"
#include "commandcompletion.h"

//Forward Declaration
Expand Down
6 changes: 3 additions & 3 deletions mosh/src/Makefile.in
Expand Up @@ -27,9 +27,9 @@ clean:
-rm -f *.o *~ core *.core $(PROG)$(EXEEXT) $(builddir_bin)/$(PROG)$(EXEEXT)


mosh.o : mosh.cpp
options.o: options.cpp
omcinteractiveenvironment.o: omcinteractiveenvironment.cpp
mosh.o : mosh.cpp options.h omcinteractiveenvironment.h
options.o: options.cpp options.h
omcinteractiveenvironment.o: omcinteractiveenvironment.cpp options.h omcinteractiveenvironment.h


.PRECIOUS: Makefile
Expand Down
2 changes: 1 addition & 1 deletion mosh/src/mosh.cpp
Expand Up @@ -103,7 +103,7 @@ int main(int argc, char* argv[])

void doOMCCommunication(const string *scriptname)
{
IAEX::OmcInteractiveEnvironment *env = IAEX::OmcInteractiveEnvironment::getInstance();
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
env->evalExpression("setCommandLineOptions(\"+d=shortOutput\")");
string cmdLine = env->getResult();
cout << "Set shortOutput flag: " << cmdLine.c_str() << std::endl;
Expand Down
54 changes: 27 additions & 27 deletions mosh/src/omcinteractiveenvironment.cpp
Expand Up @@ -33,6 +33,7 @@
//STD Headers
#include <exception>
#include <stdexcept>
#include <algorithm>

#include "omcinteractiveenvironment.h"
#ifndef WIN32
Expand All @@ -45,17 +46,16 @@ void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warn
void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_function;
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
int omc_Main_handleCommand(void *threadData, void *imsg, void *ist, void **omsg, void **ost);
void* omc_Main_init(void *threadData, void *args);
void* omc_Main_readSettings(void *threadData, void *args);
modelica_metatype omc_Main_init(void *threadData, modelica_metatype args);
modelica_metatype omc_Main_readSettings(void *threadData, modelica_metatype args);
#ifdef WIN32
void omc_Main_setWindowsPaths(threadData_t *threadData, void* _inOMHome);
#endif
}
string trim(string str);
bool contains(string s1, string s2);

namespace IAEX
{
static std::string trim(std::string str);
static bool contains(std::string s1, std::string s2);

OmcInteractiveEnvironment* OmcInteractiveEnvironment::selfInstance = NULL;
OmcInteractiveEnvironment* OmcInteractiveEnvironment::getInstance()
{
Expand All @@ -72,7 +72,7 @@ namespace IAEX
*/
OmcInteractiveEnvironment::OmcInteractiveEnvironment():result_(""),error_("")
{
void *args = mmc_mk_nil();
modelica_metatype args = mmc_mk_nil();
/* modifying args leads to a crash!!!
// set the language by reading the OMEdit settings file.
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "openmodelica", "omedit");
Expand All @@ -81,7 +81,7 @@ namespace IAEX
string locale = "+locale=" + settingsLocale.name();
args = mmc_mk_cons(mmc_mk_scon(locale.toStdString().c_str()), args);
*/
//string locale = "+locale=C";
//std::string locale = "+locale=C";
//args = mmc_mk_cons(mmc_mk_scon(locale.c_str()), args);

// initialize threadData
Expand All @@ -99,7 +99,7 @@ namespace IAEX
evalExpression("setCommandLineOptions(\"+d=initialization\")");
#ifdef WIN32
evalExpression("getInstallationDirectoryPath()");
string result = getResult();
std::string result = getResult();
//result = result.remove( "\"" );
result.erase(std::remove(result.begin(), result.end(), '\"'), result.end());
MMC_TRY_TOP_INTERNAL()
Expand All @@ -110,7 +110,7 @@ namespace IAEX

OmcInteractiveEnvironment::~OmcInteractiveEnvironment() { }

string OmcInteractiveEnvironment::getResult() {
std::string OmcInteractiveEnvironment::getResult() {
return result_;
}

Expand All @@ -120,7 +120,7 @@ namespace IAEX
*
*\brief Method for get error message from OMC
*/
string OmcInteractiveEnvironment::getError() {
std::string OmcInteractiveEnvironment::getError() {
return error_;
}

Expand All @@ -144,7 +144,7 @@ namespace IAEX
*
* 2006-02-02 AF, Added try-catch statement
*/
void OmcInteractiveEnvironment::evalExpression(const string expr) {
void OmcInteractiveEnvironment::evalExpression(const std::string expr) {
error_.clear(); // clear any error!
// call OMC with expression
void *reply_str = NULL;
Expand Down Expand Up @@ -198,53 +198,53 @@ namespace IAEX
*
*\brief Ststic method for returning the version of omc
*/
string OmcInteractiveEnvironment::OMCVersion()
std::string OmcInteractiveEnvironment::OMCVersion()
{
string version( "(version)" );
std::string version( "(version)" );

try
{
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
string getVersion = "getVersion()";
std::string getVersion = "getVersion()";
env->evalExpression( getVersion );
version = env->getResult();
//version.remove( "\"" );
version.erase(std::remove(version.begin(), version.end(), '\"'), version.end());
//delete env;
}
catch( exception &e )
catch( std::exception &e )
{
e.what();
cerr << "Unable to get OMC version, OMC is not started." << endl;
std::cerr << "Unable to get OMC version, OMC is not started." << std::endl;
}

return version;
}

string OmcInteractiveEnvironment::OpenModelicaHome()
std::string OmcInteractiveEnvironment::OpenModelicaHome()
{
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
env->evalExpression("getInstallationDirectoryPath()");
string result = env->getResult();
std::string result = env->getResult();
//result = result.remove( "\"" );
result.erase(std::remove(result.begin(), result.end(), '\"'), result.end());
return result;
}

string OmcInteractiveEnvironment::TmpPath()
std::string OmcInteractiveEnvironment::TmpPath()
{
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
env->evalExpression("getTempDirectoryPath()");
string result = env->getResult();
std::string result = env->getResult();
//result = result.replace("\\", "/");
result.replace( result.begin(), result.end(), '\\', '/');
//result.remove( "\"" );
result.erase(std::remove(result.begin(), result.end(), '\"'), result.end());
return result+"/OpenModelica/";
}
}

string trimRight(string str) {

std::string trimRight(std::string str) {
// trim trailing spaces
size_t endpos = str.find_last_not_of(" \t");
size_t startpos = str.find_first_not_of(" \t");
Expand All @@ -258,18 +258,18 @@ string trimRight(string str) {
}
return str;
}
string trimLeft(string str) {
std::string trimLeft(std::string str) {
// trim leading spaces
size_t startpos = str.find_first_not_of(" \t");
if( string::npos != startpos )
if( std::string::npos != startpos )
{
str = str.substr( startpos );
}
return str;
}
string trim(string str) {
std::string trim(std::string str) {
return trimLeft(trimRight(str));
}
bool contains(string s1, string s2) {
bool contains(std::string s1, std::string s2) {
return (s1.find(s2) != std::string::npos);
}
28 changes: 12 additions & 16 deletions mosh/src/omcinteractiveenvironment.h
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Copyright (c) 1998-2017, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -39,13 +39,9 @@

#include "meta/meta_modelica.h"

//using std::string;
using namespace std;

namespace IAEX
class OmcInteractiveEnvironment
{
class OmcInteractiveEnvironment
{
private:
OmcInteractiveEnvironment();
virtual ~OmcInteractiveEnvironment();
Expand All @@ -55,19 +51,19 @@ namespace IAEX
void *symbolTable_;

static OmcInteractiveEnvironment* getInstance();
virtual string getResult();
virtual string getError();
virtual std::string getResult();
virtual std::string getError();
virtual int getErrorLevel();
virtual void evalExpression(const string expr);
static string OMCVersion();
static string OpenModelicaHome();
static string TmpPath();
virtual void evalExpression(const std::string expr);
static std::string OMCVersion();
static std::string OpenModelicaHome();
static std::string TmpPath();

private:
static OmcInteractiveEnvironment* selfInstance;
string result_;
string error_;
std::string result_;
std::string error_;
int severity;
};
}
};

#endif

0 comments on commit b65dea2

Please sign in to comment.