Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean version of Gaurab PR #639 : Unifying the way we report file related errors #669

Merged
merged 8 commits into from
Jun 1, 2018
1 change: 0 additions & 1 deletion SofaKernel/framework/sofa/core/loader/BaseLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ bool BaseLoader::canLoad()
return true;
}


void BaseLoader::setFilename(std::string f)
{
m_filename.setValue(f);
Expand Down
2 changes: 2 additions & 0 deletions SofaKernel/framework/sofa/helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(HEADER_FILES
logging/ClangStyleMessageFormatter.h
logging/DefaultStyleMessageFormatter.h
logging/ExceptionMessageHandler.h
messaging/FileMessage.h
)

set(SOURCE_FILES
Expand Down Expand Up @@ -202,6 +203,7 @@ set(SOURCE_FILES
logging/LoggingMessageHandler.cpp
logging/RoutingMessageHandler.cpp
logging/ExceptionMessageHandler.cpp
messaging/FileMessage.cpp
)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
Expand Down
4 changes: 2 additions & 2 deletions SofaKernel/framework/sofa/helper/io/MeshTrian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/helper/io/MeshTrian.h>
#include <sofa/helper/messaging/FileMessage.h>
#include <sofa/helper/system/FileRepository.h>
#include <sofa/helper/system/Locale.h>
#include <cstdlib>
Expand Down Expand Up @@ -54,13 +55,12 @@ void MeshTrian::init (std::string filename)
return;
}
FILE *f = fopen(filename.c_str(), "r");
msg_error_when(!f)<<sofa::helper::messaging::FileMessage::unableToOpenFile(filename.c_str());
if (f)
{
readTrian (f);
fclose(f);
}
else
msg_error() << "File '" << filename << "' not found." ;
}

void MeshTrian::readTrian (FILE* file)
Expand Down
2 changes: 0 additions & 2 deletions SofaKernel/framework/sofa/helper/logging/Messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@

#define FILEINFO(filename, line) sofa::helper::logging::FileInfo(filename, line)

#define FILEINFO(filename, line) sofa::helper::logging::FileInfo(filename, line)

/// THESE MACRO BEASTS ARE FOR AUTOMATIC DETECTION OF MACRO NO or ONE ARGUMENTS
#define TWO_FUNC_CHOOSER(_f1, _f2 ,...) _f2
#define TWO_FUNC_RECOMPOSER(argsWithParentheses) TWO_FUNC_CHOOSER argsWithParentheses
Expand Down
43 changes: 43 additions & 0 deletions SofaKernel/framework/sofa/helper/messaging/FileMessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, development version *
* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include "FileMessage.h"

namespace sofa
{

namespace helper
{

namespace messaging
{

const std::string FileMessage::unableToOpenFile(const char* filename)
{
std::string errormsg="Can't open file '";
errormsg+=filename;
errormsg+="'.";
return errormsg;
}

} // logging
} // helper
} // sofa
51 changes: 51 additions & 0 deletions SofaKernel/framework/sofa/helper/messaging/FileMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture, development version *
* (c) 2006-2018 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef FILEMESSAGE_H
#define FILEMESSAGE_H

#include <iostream>
#include <string>
#include <sofa/helper/helper.h>

namespace sofa
{

namespace helper
{

namespace messaging
{

class SOFA_HELPER_API FileMessage
{
public:

FileMessage() {}
static const std::string unableToOpenFile(const char* filename);

};

} // logging
} // helper
} // sofa

#endif // FILEMESSAGE_H