修訂 | dfee4bd096028819be62772970142c41aaa07534 (tree) |
---|---|
時間 | 2013-07-18 12:14:02 |
作者 | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Implement the serializer for MolDSException. #31716
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1404 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -22,6 +22,9 @@ | ||
22 | 22 | #include<stdexcept> |
23 | 23 | #include<iostream> |
24 | 24 | #include<boost/format.hpp> |
25 | +#include<boost/serialization/map.hpp> | |
26 | +#include<boost/archive/text_iarchive.hpp> | |
27 | +#include<boost/archive/text_oarchive.hpp> | |
25 | 28 | #include"MolDSException.h" |
26 | 29 | #include"Enums.h" |
27 | 30 | using namespace std; |
@@ -90,4 +93,46 @@ const char* MolDSException::what() const throw(){ | ||
90 | 93 | str = ss.str(); |
91 | 94 | return str.c_str(); |
92 | 95 | } |
96 | + | |
97 | +template<class Archive> | |
98 | +void MolDSException::serialize(Archive& ar, const unsigned int ver){ | |
99 | + ar & intKeyValueMap; | |
100 | + // ar & otherKeyValueMap; | |
101 | + | |
102 | + ar & backtraceSize; | |
103 | + std::cerr << "backtraceSize:" << backtraceSize << std::endl; | |
104 | + if(!Archive::is_saving::value){ | |
105 | + backtracePtr.reset(new void*[backtraceSize]); | |
106 | + } | |
107 | + for(int i; i<backtraceSize; i++){ | |
108 | + if(Archive::is_saving::value){ | |
109 | + intptr_t p = reinterpret_cast<intptr_t>(backtracePtr[i]); | |
110 | + ar & p; | |
111 | + std::cerr << "in: " << p << std::endl; | |
112 | + } | |
113 | + else{ | |
114 | + intptr_t p; | |
115 | + ar & p; | |
116 | + std::cerr << "out:" << p << std::endl; | |
117 | + backtracePtr[i]=reinterpret_cast<void*>(p); | |
118 | + } | |
119 | + } | |
120 | +} | |
121 | + | |
122 | +void MolDSException::Serialize(std::ostream& os){ | |
123 | + boost::archive::text_oarchive oa(os); | |
124 | + std::string what = domain_error::what(); | |
125 | + std::cerr << "what:" << what << std::endl; | |
126 | + oa << what; | |
127 | + oa << (*this); | |
128 | +} | |
129 | + | |
130 | +MolDSException MolDSException::Deserialize(std::istream& is){ | |
131 | + boost::archive::text_iarchive ia(is); | |
132 | + std::string what; | |
133 | + ia >> what; | |
134 | + MolDSException e(what); | |
135 | + ia >> e; | |
136 | + return e; | |
137 | +} | |
93 | 138 | } |
@@ -20,6 +20,7 @@ | ||
20 | 20 | #define INCLUDED_MOLDSEXCEPTION |
21 | 21 | #include<map> |
22 | 22 | #include<boost/shared_array.hpp> |
23 | +#include<boost/serialization/access.hpp> | |
23 | 24 | namespace MolDS_base{ |
24 | 25 | class MolDSException : public std::domain_error { |
25 | 26 | public: |
@@ -35,6 +36,8 @@ public: | ||
35 | 36 | void SetKeyValue(int key, T value); |
36 | 37 | bool HasKey(int key); |
37 | 38 | virtual const char* what() const throw(); |
39 | + void Serialize(std::ostream& os); | |
40 | + static MolDSException Deserialize(std::istream& is); | |
38 | 41 | private: |
39 | 42 | void GetBacktrace(int bufsize); |
40 | 43 | size_t backtraceSize; |
@@ -43,6 +46,9 @@ private: | ||
43 | 46 | intKeyValueMap_t intKeyValueMap; |
44 | 47 | //typedef std::map<int, other> otherKeyValueMap_t; |
45 | 48 | //otherKeyValueMap_t otherKeyValueMap; |
49 | + friend class boost::serialization::access; | |
50 | + template<class Archive> | |
51 | + void serialize(Archive& ar, const unsigned int ver); | |
46 | 52 | }; |
47 | 53 | } |
48 | 54 | #endif |