Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lammps
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
multiscale
lammps
Commits
719d7c65
Commit
719d7c65
authored
8 years ago
by
Richard Berger
Browse files
Options
Downloads
Patches
Plain Diff
Make exceptions control flow and functions optional
parent
8db7ef43
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/error.cpp
+8
-1
8 additions, 1 deletion
src/error.cpp
src/error.h
+10
-38
10 additions, 38 deletions
src/error.h
src/exceptions.h
+58
-0
58 additions, 0 deletions
src/exceptions.h
src/library.cpp
+7
-0
7 additions, 0 deletions
src/library.cpp
src/library.h
+2
-0
2 additions, 0 deletions
src/library.h
with
85 additions
and
39 deletions
src/error.cpp
+
8
−
1
View file @
719d7c65
...
...
@@ -22,7 +22,12 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
Error
::
Error
(
LAMMPS
*
lmp
)
:
Pointers
(
lmp
),
last_error_message
(
NULL
),
last_error_type
(
ERROR_NONE
)
{}
Error
::
Error
(
LAMMPS
*
lmp
)
:
Pointers
(
lmp
)
{
#ifdef LAMMPS_EXCEPTIONS
last_error_message
=
NULL
;
last_error_type
=
ERROR_NONE
;
#endif
}
/* ----------------------------------------------------------------------
called by all procs in universe
...
...
@@ -198,6 +203,7 @@ void Error::done(int status)
exit
(
status
);
}
#ifdef LAMMPS_EXCEPTIONS
/* ----------------------------------------------------------------------
return the last error message reported by LAMMPS (only used if
compiled with -DLAMMPS_EXCEPTIONS)
...
...
@@ -235,3 +241,4 @@ void Error::set_last_error(const char * msg, ErrorType type)
}
last_error_type
=
type
;
}
#endif
This diff is collapsed.
Click to expand it.
src/error.h
+
10
−
38
View file @
719d7c65
...
...
@@ -15,48 +15,14 @@
#define LMP_ERROR_H
#include
"pointers.h"
#include
<string>
#include
<exception>
namespace
LAMMPS_NS
{
class
LAMMPSException
:
public
std
::
exception
{
public:
std
::
string
message
;
LAMMPSException
(
std
::
string
msg
)
:
message
(
msg
)
{
}
~
LAMMPSException
()
throw
()
{
}
virtual
const
char
*
what
()
const
throw
()
{
return
message
.
c_str
();
}
};
class
LAMMPSAbortException
:
public
LAMMPSException
{
public:
MPI_Comm
universe
;
LAMMPSAbortException
(
std
::
string
msg
,
MPI_Comm
universe
)
:
LAMMPSException
(
msg
),
universe
(
universe
)
{
}
};
#ifdef LAMMPS_EXCEPTIONS
#include
"exceptions.h"
#endif
enum
ErrorType
{
ERROR_NONE
=
0
,
ERROR_NORMAL
=
1
,
ERROR_ABORT
=
2
};
namespace
LAMMPS_NS
{
class
Error
:
protected
Pointers
{
char
*
last_error_message
;
ErrorType
last_error_type
;
public:
Error
(
class
LAMMPS
*
);
...
...
@@ -70,9 +36,15 @@ class Error : protected Pointers {
void
message
(
const
char
*
,
int
,
const
char
*
,
int
=
1
);
void
done
(
int
=
0
);
// 1 would be fully backwards compatible
#ifdef LAMMPS_EXCEPTIONS
char
*
get_last_error
()
const
;
ErrorType
get_last_error_type
()
const
;
void
set_last_error
(
const
char
*
msg
,
ErrorType
type
=
ERROR_NORMAL
);
private:
char
*
last_error_message
;
ErrorType
last_error_type
;
#endif
};
}
...
...
This diff is collapsed.
Click to expand it.
src/exceptions.h
0 → 100644
+
58
−
0
View file @
719d7c65
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifndef LMP_EXCEPTIONS_H
#define LMP_EXCEPTIONS_H
#include
<mpi.h>
#include
<string>
#include
<exception>
namespace
LAMMPS_NS
{
class
LAMMPSException
:
public
std
::
exception
{
public:
std
::
string
message
;
LAMMPSException
(
std
::
string
msg
)
:
message
(
msg
)
{
}
~
LAMMPSException
()
throw
()
{
}
virtual
const
char
*
what
()
const
throw
()
{
return
message
.
c_str
();
}
};
class
LAMMPSAbortException
:
public
LAMMPSException
{
public:
MPI_Comm
universe
;
LAMMPSAbortException
(
std
::
string
msg
,
MPI_Comm
universe
)
:
LAMMPSException
(
msg
),
universe
(
universe
)
{
}
};
enum
ErrorType
{
ERROR_NONE
=
0
,
ERROR_NORMAL
=
1
,
ERROR_ABORT
=
2
};
}
#endif
This diff is collapsed.
Click to expand it.
src/library.cpp
+
7
−
0
View file @
719d7c65
...
...
@@ -109,6 +109,8 @@ void lammps_file(void *ptr, char *str)
char
*
lammps_command
(
void
*
ptr
,
char
*
str
)
{
LAMMPS
*
lmp
=
(
LAMMPS
*
)
ptr
;
#ifdef LAMMPS_EXCEPTIONS
Error
*
error
=
lmp
->
error
;
try
{
...
...
@@ -127,6 +129,9 @@ char *lammps_command(void *ptr, char *str)
error
->
set_last_error
(
e
.
message
.
c_str
(),
ERROR_NORMAL
);
return
NULL
;
}
#else
return
lmp
->
input
->
one
(
str
);
#endif
}
/* ----------------------------------------------------------------------
...
...
@@ -611,6 +616,7 @@ void lammps_scatter_atoms(void *ptr, char *name,
}
}
#ifdef LAMMPS_EXCEPTIONS
/* ----------------------------------------------------------------------
Check if a new error message
------------------------------------------------------------------------- */
...
...
@@ -640,3 +646,4 @@ int lammps_get_last_error_message(void *ptr, char * buffer, int buffer_size) {
}
return
0
;
}
#endif
This diff is collapsed.
Click to expand it.
src/library.h
+
2
−
0
View file @
719d7c65
...
...
@@ -45,8 +45,10 @@ int lammps_get_natoms(void *);
void
lammps_gather_atoms
(
void
*
,
char
*
,
int
,
int
,
void
*
);
void
lammps_scatter_atoms
(
void
*
,
char
*
,
int
,
int
,
void
*
);
#ifdef LAMMPS_EXCEPTION
int
lammps_has_error
(
void
*
);
int
lammps_get_last_error_message
(
void
*
,
char
*
,
int
);
#endif
#ifdef __cplusplus
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment