• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版efca055c3be52f6ff146b88d6196513b18572b2c (tree)
时间2013-07-03 22:21:35
作者Katsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Log Message

Add key value storage in MolDSException.

更改概述

差异

--- a/src/base/MolDSException.cpp
+++ b/src/base/MolDSException.cpp
@@ -17,10 +17,12 @@
1717 // along with MolDS. If not, see <http://www.gnu.org/licenses/>. //
1818 //************************************************************************//
1919 #include<execinfo.h>
20+#include<sstream>
2021 #include<string>
2122 #include<stdexcept>
2223 #include<boost/format.hpp>
2324 #include"MolDSException.h"
25+#include"Enums.h"
2426 using namespace std;
2527 namespace MolDS_base{
2628 MolDSException::MolDSException(string cause) : domain_error(cause), backtraceSize(0){
@@ -46,5 +48,45 @@ void MolDSException::PrintBacktrace(){
4648 cout<<"backtrace:" << endl;
4749 backtrace_symbols_fd(this->backtracePtr.get(), this->backtraceSize, 1);
4850 }
51+
52+template<>
53+int MolDSException::GetKeyValue(int key){
54+ return intKeyValueMap[key];
55+}
56+
57+/*
58+template<>
59+other MolDSException::GetKeyValue(int key){
60+ return otherKeyValueMap[key];
61+}
62+*/
63+
64+template<>
65+void MolDSException::SetKeyValue(int key, int value){
66+ intKeyValueMap[key]=value;
67+}
68+
69+/*
70+template<>
71+void MolDSException::SetKeyValue(int key, other value){
72+ otherKeyValueMap.insert(otherKeyValueMap::pair(key,value));
73+}
74+*/
75+
76+bool MolDSException::HasKey(int key){
77+ if(!(intKeyValueMap.find(key)==intKeyValueMap.end())) return true;
78+ //if(otherKeyValueMap.find(key)!=otherKeyValueMap::end) return true;
79+ return false;
4980 }
5081
82+const char* MolDSException::what() const throw(){
83+ static string str;
84+ stringstream ss;
85+ ss << domain_error::what() << "key value pairs:";
86+ for(intKeyValueMap_t::const_iterator i = intKeyValueMap.begin(); i != intKeyValueMap.end(); i++){
87+ ss << endl << '\t' << ExceptionKeyStr(i->first) << ":" << i->second;
88+ }
89+ str = ss.str();
90+ return str.c_str();
91+}
92+}
--- a/src/base/MolDSException.h
+++ b/src/base/MolDSException.h
@@ -18,6 +18,7 @@
1818 //************************************************************************//
1919 #ifndef INCLUDED_MOLDSEXCEPTION
2020 #define INCLUDED_MOLDSEXCEPTION
21+#include<map>
2122 #include<boost/shared_array.hpp>
2223 namespace MolDS_base{
2324 class MolDSException : public std::domain_error {
@@ -28,10 +29,20 @@ public:
2829 #endif
2930 ~MolDSException() throw(){};
3031 void PrintBacktrace();
32+ template <class T>
33+ T GetKeyValue(int key);
34+ template <class T>
35+ void SetKeyValue(int key, T value);
36+ bool HasKey(int key);
37+ virtual const char* what() const throw();
3138 private:
3239 void GetBacktrace(int bufsize);
3340 size_t backtraceSize;
3441 boost::shared_array<void*> backtracePtr;
42+ typedef std::map<int, int> intKeyValueMap_t;
43+ intKeyValueMap_t intKeyValueMap;
44+ //typedef std::map<int, other> otherKeyValueMap_t;
45+ //otherKeyValueMap_t otherKeyValueMap;
3546 };
3647 }
3748 #endif