source: src/Helpers/Assert.cpp@ 10d290

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 10d290 was 839e85, checked in by Tillmann Crueger <crueger@…>, 14 years ago

Removed some unecessary opened namespaces

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Assert.cpp
3 *
4 * Created on: Mar 18, 2010
5 * Author: crueger
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "Helpers/Assert.hpp"
11#include <iostream>
12
13using namespace std;
14
15namespace Assert{
16 AssertionFailure::AssertionFailure(std::string _condition,
17 std::string _file,
18 int _line,
19 std::string _message) :
20 condition(_condition),
21 file(_file),
22 line(_line),
23 message(_message)
24 {}
25
26 std::string AssertionFailure::getFile(){
27 return file;
28 }
29
30 int AssertionFailure::getLine(){
31 return line;
32 }
33
34 std::string AssertionFailure::getMessage(){
35 return message;
36 }
37
38 std::ostream& AssertionFailure::operator<<(std::ostream& out){
39 out << "Assertion \"" << condition << "\" failed in file " << file << " at line " << line << endl;
40 out << "Assertion Message: " << message << std::endl;
41 return out;
42 }
43
44 const char ActionKeys[] = {'\0','a','t','i'};
45 const char* ActionNames[] = {"Ask","Abort","Throw","Ignore"};
46}
47
48#ifndef NDEBUG
49
50Assert::Action Assert::_my_assert::defaultAction = Ask;
51std::vector<Assert::hook_t> Assert::_my_assert::hooks;
52
53std::map<std::string,bool> Assert::_wrapper::ignores;
54const char* Assert::_wrapper::message_ptr = "source pointer did not point to object of desired type";
55const char* Assert::_wrapper::message_ref = "source reference did not contain object of desired type";
56
57
58bool Assert::_my_assert::check(const bool res,
59 const char* condition,
60 const char* message,
61 const char* filename,
62 const int line,
63 bool& ignore)
64{
65 if(!res){
66 cout << "Assertion \"" << condition << "\" failed in file " << filename << " at line " << line << endl;
67 cout << "Assertion Message: " << message << std::endl;
68 while(true){
69 char choice;
70 if(defaultAction==Assert::Ask) {
71 cout << "Please choose: (a)bort, (t)hrow execption, (i)gnore, al(w)ays ignore" << endl;
72 cin >> choice;
73 }
74 else{
75 choice = ActionKeys[defaultAction];
76 }
77 switch(choice){
78 case 'a':
79 return true;
80 break;
81 case 't':
82 throw AssertionFailure(condition,filename,line,message);
83 break;
84 case 'w':
85 ignore = true;
86 // fallthrough
87 case 'i':
88 return false;
89 break;
90 }
91 }
92 }
93 return false;
94}
95
96void Assert::_my_assert::doHooks(){
97 for(vector<hook_t>::reverse_iterator iter = hooks.rbegin(); iter!=hooks.rend(); ++iter ){
98 (*iter)();
99 }
100}
101
102void Assert::_my_assert::addHook(hook_t hook){
103 hooks.push_back(hook);
104}
105
106void Assert::_my_assert::removeHook(Assert::hook_t hook){
107 for(vector<hook_t>::iterator iter = hooks.begin(); iter!=hooks.end();){
108 if((*iter)==hook){
109 iter = hooks.erase(iter);
110 }
111 else{
112 ++iter;
113 }
114 }
115}
116
117void Assert::_my_assert::setDefault(Assert::Action action){
118 defaultAction = action;
119}
120Assert::Action Assert::_my_assert::getDefault(){
121 return defaultAction;
122}
123std::string Assert::_my_assert::printDefault(){
124 return ActionNames[defaultAction];
125}
126
127#endif
128
Note: See TracBrowser for help on using the repository browser.