Commit 19ff5a45 authored by Mohcine Chraibi's avatar Mohcine Chraibi

Unified Formatting with astyle

Stroustrup style formatting/indenting is used. Adapt your editor to use this style.
For eclipse there is a plugin for astyle http://sourceforge.net/projects/astyleclipse/

See also http://astyle.sourceforge.net/astyle.html
parent d9a7b185
......@@ -77,36 +77,41 @@ if(DOXYGEN_FOUND)
)
endif(DOXYGEN_FOUND)
#find the correct OpenMP flag
# find the correct OpenMP flag
FIND_PACKAGE(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else(OPENMP_FOUND)
message( STATUS "Disabling OpenMP support" )
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
# somehow find_package(openmp) does not work properly with clang
else(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message( STATUS "Disabling OpenMP support" )
endif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif(OPENMP_FOUND)
#find and add the CGAL library
# find and add the CGAL library
#fixme: complete this section
FIND_PACKAGE(CGAL QUIET)
if(CGAL_FOUND)
include (${CGAL_USE_FILE})
INCLUDE_DIRECTORIES(${CGAL_CORE_INCLUDE_DIR})
add_definitions(-D_CGAL=1)
message (SEND_ERROR "${CGAL_FOUND}")
message (FATAL_ERROR "${CGAL_CORE_INCLUDE_DIR}")
message (SEND_ERROR " Erreur: ${CGAL_FOUND}")
message (SEND_ERROR " Erreur: ${CGAL_USE_FILE}")
else(CGAL_FOUND)
message( STATUS "CGAL not found. But don't panik .." )
endif(CGAL_FOUND)
# test files: all cpp-files in Utest
# FIND_PACKAGE(CGAL QUIET)
# if(CGAL_FOUND)
# include (${CGAL_USE_FILE})
# INCLUDE_DIRECTORIES(${CGAL_CORE_INCLUDE_DIR})
# add_definitions(-D_CGAL=1)
# message (STATUS "${CGAL_FOUND}")
# message (STATUS "${CGAL_CORE_INCLUDE_DIR}")
# message (STATUS " Erreur: ${CGAL_FOUND}")
# message (STATUS " Erreur: ${CGAL_USE_FILE}")
# else(CGAL_FOUND)
# message( STATUS "CGAL not found." )
# endif(CGAL_FOUND)
# test all cpp-files in Utest
if(BUILD_TESTING)
file(GLOB test_files "${CMAKE_TEST_DIR}/*.cpp")
endif(BUILD_TESTING)
# add sources and headers
set ( source_files
main.cpp
Simulation.cpp
......@@ -275,30 +280,43 @@ if(CGAL_FOUND)
target_link_libraries (jpscore ${CGAL_CORE_LIBRARY})
endif(CGAL_FOUND)
#---------------------------- compiler -------------------------------
# Initialize CXXFLAGS.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wunused-variable -Wunused-parameter -Wunused-function -Wunused")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
# check c++-11
if((CMAKE_COMPILER_IS_GNUCXX AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.6) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.1))
message(STATUS "Checking for C++11 compiler - available")
else()
message(STATUS "Checking for C++11 compiler - unavailable")
endif()
# c++-11 flags
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "Using CLANG++" )
message(STATUS "Using Clang" )
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCXX)
message( STATUS "Set compiler flags (g++)" )
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=c++11")
message( STATUS "Using g++" )
endif(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE MATCHES Debug)
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "In Debug Build")
set(WITH_COVERAGE TRUE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage -std=c++11")
set(CMAKE_CXX_LDFLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
message(STATUS "Debug flags for coverage: " ${CMAKE_CXX_FLAGS_DEBUG} )
else(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Release flags: " ${CMAKE_CXX_FLAGS_RELEASE} )
endif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Debug flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_DEBUG} )
else(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Release flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_RELEASE} )
endif(CMAKE_BUILD_TYPE MATCHES Debug)
# ----------------------------- cTest ------------------------------------------
if(BUILD_TESTING)
enable_testing() #adds another build target, which is test for Makefile generators
include(CTest) #adding Dart support
enable_testing() # adds another build target, which is test for Makefile generators
include(CTest) # adding Dart support
#test if code compiles and runs default setting. Takes about 30 seconds
# test if code compiles and runs default setting. Takes about 30 seconds
add_test (jpscore_compile ${CMAKE_CTEST_COMMAND}
--build-and-test "${CMAKE_SOURCE_DIR}" "${EXECUTABLE_OUTPUT_PATH}" #"${CMAKE_BINARY_DIR}"
--build-generator ${CMAKE_GENERATOR}
......
This diff is collapsed.
......@@ -38,35 +38,35 @@
extern OutputHandler* Log;
class IODispatcher {
private:
std::vector<OutputHandler* > pHandlers;
std::string WritePed(Pedestrian* ped);
public:
IODispatcher();
IODispatcher(const IODispatcher& orig);
virtual ~IODispatcher();
void AddIO(OutputHandler* ioh);
const std::vector<OutputHandler*>& GetIOHandlers();
void Write(const std::string& str);
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
int AreaLevel(std::string caption);
template<typename A>
bool IsElementInVector(const std::vector<A> &vec, A& el) {
typename std::vector<A>::const_iterator it;
it = std::find (vec.begin(), vec.end(), el);
if(it==vec.end()){
return false;
}else{
return true;
}
}
private:
std::vector<OutputHandler* > pHandlers;
std::string WritePed(Pedestrian* ped);
public:
IODispatcher();
IODispatcher(const IODispatcher& orig);
virtual ~IODispatcher();
void AddIO(OutputHandler* ioh);
const std::vector<OutputHandler*>& GetIOHandlers();
void Write(const std::string& str);
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
int AreaLevel(std::string caption);
template<typename A>
bool IsElementInVector(const std::vector<A> &vec, A& el) {
typename std::vector<A>::const_iterator it;
it = std::find (vec.begin(), vec.end(), el);
if(it==vec.end()) {
return false;
} else {
return true;
}
}
};
......@@ -74,53 +74,53 @@ class IODispatcher {
class TrajectoriesFLAT:public IODispatcher {
public:
TrajectoriesFLAT();
virtual ~TrajectoriesFLAT(){};
public:
TrajectoriesFLAT();
virtual ~TrajectoriesFLAT() {};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
class TrajectoriesVTK:public IODispatcher {
public:
TrajectoriesVTK();
virtual ~TrajectoriesVTK(){};
public:
TrajectoriesVTK();
virtual ~TrajectoriesVTK() {};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
class TrajectoriesXML_MESH:public IODispatcher {
public:
TrajectoriesXML_MESH(){};
virtual ~TrajectoriesXML_MESH(){};
public:
TrajectoriesXML_MESH() {};
virtual ~TrajectoriesXML_MESH() {};
//virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
//virtual void WriteFrame(int frameNr, Building* building);
//virtual void WriteFooter();
virtual void WriteGeometry(Building* building);
//virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
//virtual void WriteFrame(int frameNr, Building* building);
//virtual void WriteFooter();
virtual void WriteGeometry(Building* building);
};
class TrajectoriesJPSV06: public IODispatcher {
public:
TrajectoriesJPSV06(){};
virtual ~TrajectoriesJPSV06(){};
public:
TrajectoriesJPSV06() {};
virtual ~TrajectoriesJPSV06() {};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
#endif /* _IODISPATCHER_H */
......
......@@ -34,92 +34,101 @@
using namespace std;
void OutputHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
void OutputHandler::Write(string str)
{
if (this != NULL)
cout << str << endl;
}
void OutputHandler::Write(const char* message,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, message);
vsprintf (msg,message ,ap);
va_end (ap);
string str(msg);
if(str.find("ERROR")==string::npos) {
cout<<msg<<endl;
cout.flush();
}
else {
cerr<<msg<<endl;
cerr.flush();
}
//cout << "\033[1;30mbold red text\033[0m\n";
//cout << "\033[1;31"<<msg<<"\033[0m\n";
//cout << "\033[1;31 bla bla \033[0m\n";
void OutputHandler::Write(const char* message,...)
{
char msg[CLENGTH];
va_list ap;
va_start (ap, message);
vsprintf (msg,message ,ap);
va_end (ap);
string str(msg);
if(str.find("ERROR")==string::npos) {
cout<<msg<<endl;
cout.flush();
} else {
cerr<<msg<<endl;
cerr.flush();
}
//cout << "\033[1;30mbold red text\033[0m\n";
//cout << "\033[1;31"<<msg<<"\033[0m\n";
//cout << "\033[1;31 bla bla \033[0m\n";
}
void STDIOHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
void STDIOHandler::Write(string str)
{
if (this != NULL)
cout << str << endl;
}
FileHandler::FileHandler(const char *fn) {
pfp.open(fn);
if (!fn) {
char tmp[CLENGTH];
sprintf(tmp, "Error!!! File [%s] could not be opened!", fn);
cerr << tmp << endl;
exit(0);
}
FileHandler::FileHandler(const char *fn)
{
pfp.open(fn);
if (!fn) {
char tmp[CLENGTH];
sprintf(tmp, "Error!!! File [%s] could not be opened!", fn);
cerr << tmp << endl;
exit(0);
}
}
FileHandler::~FileHandler() {
pfp.close();
FileHandler::~FileHandler()
{
pfp.close();
}
void FileHandler::Write(string str) {
if (this != NULL) {
pfp << str << endl;
pfp.flush();
}
void FileHandler::Write(string str)
{
if (this != NULL) {
pfp << str << endl;
pfp.flush();
}
}
void FileHandler::Write(const char* string,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, string);
vsprintf (msg,string ,ap);
va_end (ap);
pfp<<msg<<endl;
pfp.flush();
void FileHandler::Write(const char* string,...)
{
char msg[CLENGTH];
va_list ap;
va_start (ap, string);
vsprintf (msg,string ,ap);
va_end (ap);
pfp<<msg<<endl;
pfp.flush();
}
TraVisToHandler::TraVisToHandler(string host, int port) {
client = new TraVisToClient(host, port);
brokentags.push_back("<trajectories>");
brokentags.push_back("</trajectories>");
brokentags.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
TraVisToHandler::TraVisToHandler(string host, int port)
{
client = new TraVisToClient(host, port);
brokentags.push_back("<trajectories>");
brokentags.push_back("</trajectories>");
brokentags.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
TraVisToHandler::~TraVisToHandler(){
delete client;
TraVisToHandler::~TraVisToHandler()
{
delete client;
}
void TraVisToHandler::Write(string str) {
void TraVisToHandler::Write(string str)
{
vector<string>::iterator str_it;
vector<string>::iterator str_it;
//There are a few broken tags which need to be checked for and removed.
for (str_it = brokentags.begin(); str_it != brokentags.end(); ++str_it) {
int tagstart = str.find(*str_it);
if (tagstart != (int) string::npos) {
str.erase(str.begin() + tagstart, str.begin() + tagstart + (*str_it).size());
}
}
client->sendData(str.c_str());
//There are a few broken tags which need to be checked for and removed.
for (str_it = brokentags.begin(); str_it != brokentags.end(); ++str_it) {
int tagstart = str.find(*str_it);
if (tagstart != (int) string::npos) {
str.erase(str.begin() + tagstart, str.begin() + tagstart + (*str_it).size());
}
}
client->sendData(str.c_str());
}
......
......@@ -37,39 +37,39 @@
#include "../general/Macros.h"
class OutputHandler {
public:
virtual void Write(std::string str);
virtual void Write(const char *string, ...);
virtual ~OutputHandler(){};
public:
virtual void Write(std::string str);
virtual void Write(const char *string, ...);
virtual ~OutputHandler() {};
};
class STDIOHandler : public OutputHandler {
public:
void Write(std::string str);
public:
void Write(std::string str);
};
class FileHandler : public OutputHandler {
private:
std::ofstream pfp;
public:
FileHandler(const char *fn);
virtual ~FileHandler();
void Write(std::string str);
void Write(const char *string,...);
private:
std::ofstream pfp;
public:
FileHandler(const char *fn);
virtual ~FileHandler();
void Write(std::string str);
void Write(const char *string,...);
};
class TraVisToHandler : public OutputHandler {
private:
TraVisToClient* client;
private:
TraVisToClient* client;
public:
TraVisToHandler(std::string host, int port);
virtual ~TraVisToHandler();
void Write(std::string str);
public:
TraVisToHandler(std::string host, int port);
virtual ~TraVisToHandler();
void Write(std::string str);
//Some tags are broken
std::vector<std::string> brokentags;
//Some tags are broken
std::vector<std::string> brokentags;
};
......
This diff is collapsed.
......@@ -91,58 +91,58 @@ typedef int socket_t;
#define HOST "localhost"
class TraVisToClient {
public:
public:
/// create a client with specific parameters
TraVisToClient(std::string hostname = HOST, unsigned short port = PORT);
/// create a client with specific parameters
TraVisToClient(std::string hostname = HOST, unsigned short port = PORT);
/// Destructor
virtual ~TraVisToClient();
/// Destructor
virtual ~TraVisToClient();
/// send datablock to the server
/// this functions is still blocking unfortunately, so it may
/// influence the execution time of your program
void sendData(const char* data);
/// send datablock to the server
/// this functions is still blocking unfortunately, so it may
/// influence the execution time of your program
void sendData(const char* data);
/// close the client (end the connection)
void close();
/// close the client (end the connection)
void close();
/// send a datagram using the unreliable
/// udp protokoll
void sendDatagram(char *datagram);
/// send a datagram using the unreliable
/// udp protokoll
void sendDatagram(char *datagram);
private:
void createConnection();
private:
void createConnection();
unsigned long lookupHostAddress(const char *hostName);
unsigned long lookupHostAddress(const char *hostName);
socket_t createClientSocket(const char *serverName, unsigned short portNumber);
socket_t createClientSocket(const char *serverName, unsigned short portNumber);
socket_t createServerSocket(unsigned short portNumber);
socket_t createServerSocket(unsigned short portNumber);
bool shutdownAndCloseSocket(socket_t sock);
bool shutdownAndCloseSocket(socket_t sock);
bool sendMessage(socket_t sock, const void *msg, int msgSize);
bool sendMessage(socket_t sock, const void *msg, int msgSize);
bool receiveMessage(socket_t sock, void *msg, int msgSize);
bool receiveMessage(socket_t sock, void *msg, int msgSize);
void _printErrorMessage(void);
void _printErrorMessage(void);
#ifdef _WIN32
bool _startWin32SocketSession(void);
void _stopWin32SocketSession(void);
bool _startWin32SocketSession(void);
void _stopWin32SocketSession(void);
#else
#define closesocket close
#endif
private:
bool _isConnected;
socket_t _tcpSocket;
std::string _hostname;
unsigned short _port;
std::vector<const char *> _msgQueue;
private:
bool _isConnected;
socket_t _tcpSocket;
std::string _hostname;
unsigned short _port;