File indexing completed on 2025-01-18 09:28:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <algorithm>
0012 #include <cstddef> // NULL
0013 #include <cstring>
0014 #if defined(BOOST_NO_STDC_NAMESPACE) && ! defined(__LIBCOMO__)
0015 namespace std{
0016 using ::strlen;
0017 }
0018 #endif
0019
0020 #include <boost/archive/basic_xml_archive.hpp>
0021 #include <boost/archive/basic_xml_oarchive.hpp>
0022 #include <boost/archive/xml_archive_exception.hpp>
0023 #include <boost/core/no_exceptions_support.hpp>
0024
0025 namespace boost {
0026 namespace archive {
0027
0028 namespace detail {
0029 template<class CharType>
0030 struct XML_name {
0031 void operator()(CharType t) const{
0032 const unsigned char lookup_table[] = {
0033 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0034 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0035 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,
0036 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
0037 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0038 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,
0039 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0040 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
0041 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0042 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
0043 };
0044 if((unsigned)t > 127)
0045 return;
0046 if(0 == lookup_table[(unsigned)t])
0047 boost::serialization::throw_exception(
0048 xml_archive_exception(
0049 xml_archive_exception::xml_archive_tag_name_error
0050 )
0051 );
0052 }
0053 };
0054
0055 }
0056
0057
0058
0059
0060 template<class Archive>
0061 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0062 basic_xml_oarchive<Archive>::write_attribute(
0063 const char *attribute_name,
0064 int t,
0065 const char *conjunction
0066 ){
0067 this->This()->put(' ');
0068 this->This()->put(attribute_name);
0069 this->This()->put(conjunction);
0070 this->This()->save(t);
0071 this->This()->put('"');
0072 }
0073
0074 template<class Archive>
0075 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0076 basic_xml_oarchive<Archive>::write_attribute(
0077 const char *attribute_name,
0078 const char *key
0079 ){
0080 this->This()->put(' ');
0081 this->This()->put(attribute_name);
0082 this->This()->put("=\"");
0083 this->This()->save(key);
0084 this->This()->put('"');
0085 }
0086
0087 template<class Archive>
0088 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0089 basic_xml_oarchive<Archive>::indent(){
0090 int i;
0091 for(i = depth; i-- > 0;)
0092 this->This()->put('\t');
0093 }
0094
0095 template<class Archive>
0096 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0097 basic_xml_oarchive<Archive>::save_start(const char *name)
0098 {
0099 if(NULL == name)
0100 return;
0101
0102
0103 std::for_each(name, name + std::strlen(name), detail::XML_name<const char>());
0104
0105 end_preamble();
0106 if(depth > 0){
0107 this->This()->put('\n');
0108 indent();
0109 }
0110 ++depth;
0111 this->This()->put('<');
0112 this->This()->save(name);
0113 pending_preamble = true;
0114 indent_next = false;
0115 }
0116
0117 template<class Archive>
0118 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0119 basic_xml_oarchive<Archive>::save_end(const char *name)
0120 {
0121 if(NULL == name)
0122 return;
0123
0124
0125 std::for_each(name, name + std::strlen(name), detail::XML_name<const char>());
0126
0127 end_preamble();
0128 --depth;
0129 if(indent_next){
0130 this->This()->put('\n');
0131 indent();
0132 }
0133 indent_next = true;
0134 this->This()->put("</");
0135 this->This()->save(name);
0136 this->This()->put('>');
0137 if(0 == depth)
0138 this->This()->put('\n');
0139 }
0140
0141 template<class Archive>
0142 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0143 basic_xml_oarchive<Archive>::end_preamble(){
0144 if(pending_preamble){
0145 this->This()->put('>');
0146 pending_preamble = false;
0147 }
0148 }
0149 #if 0
0150 template<class Archive>
0151 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0152 basic_xml_oarchive<Archive>::save_override(const object_id_type & t)
0153 {
0154 int i = t.t;
0155 write_attribute(BOOST_ARCHIVE_XML_OBJECT_ID(), i, "=\"_");
0156 }
0157 template<class Archive>
0158 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0159 basic_xml_oarchive<Archive>::save_override(
0160 const object_reference_type & t,
0161 int
0162 ){
0163 int i = t.t;
0164 write_attribute(BOOST_ARCHIVE_XML_OBJECT_REFERENCE(), i, "=\"_");
0165 }
0166 template<class Archive>
0167 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0168 basic_xml_oarchive<Archive>::save_override(const version_type & t)
0169 {
0170 int i = t.t;
0171 write_attribute(BOOST_ARCHIVE_XML_VERSION(), i);
0172 }
0173 #endif
0174
0175 template<class Archive>
0176 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0177 basic_xml_oarchive<Archive>::save_override(const object_id_type & t)
0178 {
0179
0180 const unsigned int i = t;
0181 write_attribute(BOOST_ARCHIVE_XML_OBJECT_ID(), i, "=\"_");
0182 }
0183 template<class Archive>
0184 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0185 basic_xml_oarchive<Archive>::save_override(
0186 const object_reference_type & t
0187 ){
0188 const unsigned int i = t;
0189 write_attribute(BOOST_ARCHIVE_XML_OBJECT_REFERENCE(), i, "=\"_");
0190 }
0191 template<class Archive>
0192 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0193 basic_xml_oarchive<Archive>::save_override(const version_type & t)
0194 {
0195 const unsigned int i = t;
0196 write_attribute(BOOST_ARCHIVE_XML_VERSION(), i);
0197 }
0198
0199 template<class Archive>
0200 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0201 basic_xml_oarchive<Archive>::save_override(const class_id_type & t)
0202 {
0203 write_attribute(BOOST_ARCHIVE_XML_CLASS_ID(), t);
0204 }
0205 template<class Archive>
0206 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0207 basic_xml_oarchive<Archive>::save_override(
0208 const class_id_reference_type & t
0209 ){
0210 write_attribute(BOOST_ARCHIVE_XML_CLASS_ID_REFERENCE(), t);
0211 }
0212 template<class Archive>
0213 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0214 basic_xml_oarchive<Archive>::save_override(
0215 const class_id_optional_type & t
0216 ){
0217 write_attribute(BOOST_ARCHIVE_XML_CLASS_ID(), t);
0218 }
0219 template<class Archive>
0220 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0221 basic_xml_oarchive<Archive>::save_override(const class_name_type & t)
0222 {
0223 const char * key = t;
0224 if(NULL == key)
0225 return;
0226 write_attribute(BOOST_ARCHIVE_XML_CLASS_NAME(), key);
0227 }
0228
0229 template<class Archive>
0230 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0231 basic_xml_oarchive<Archive>::save_override(const tracking_type & t)
0232 {
0233 write_attribute(BOOST_ARCHIVE_XML_TRACKING(), t.t);
0234 }
0235
0236 template<class Archive>
0237 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0238 basic_xml_oarchive<Archive>::init(){
0239
0240 this->This()->put("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n");
0241 this->This()->put("<!DOCTYPE boost_serialization>\n");
0242
0243 this->This()->put("<boost_serialization");
0244 write_attribute("signature", BOOST_ARCHIVE_SIGNATURE());
0245 write_attribute("version", BOOST_ARCHIVE_VERSION());
0246 this->This()->put(">\n");
0247 }
0248
0249 template<class Archive>
0250 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0251 basic_xml_oarchive<Archive>::windup(){
0252
0253 this->This()->put("</boost_serialization>\n");
0254 }
0255
0256 template<class Archive>
0257 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0258 basic_xml_oarchive<Archive>::basic_xml_oarchive(unsigned int flags) :
0259 detail::common_oarchive<Archive>(flags),
0260 depth(0),
0261 pending_preamble(false),
0262 indent_next(false)
0263 {
0264 }
0265
0266 template<class Archive>
0267 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0268 basic_xml_oarchive<Archive>::~basic_xml_oarchive(){
0269 }
0270
0271 }
0272 }