xml_o_file.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "io_common.h"
00044 #include "xml_o_file.h"
00045 #include "../util/bit_manip.h"
00046
00047 namespace lass
00048 {
00049 namespace io
00050 {
00051
00052
00053
00054 XmlOFile::XmlOFile():
00055 XmlOStream(),
00056 file_(),
00057 root_("")
00058 {
00059 }
00060
00061
00062
00063 XmlOFile::XmlOFile(const char* iFileName, std::ios::openmode iOpenMode):
00064 XmlOStream()
00065 {
00066 open(iFileName, iOpenMode);
00067 }
00068
00069
00070
00071 XmlOFile::XmlOFile(const char* iFileName, const char* iRoot):
00072 XmlOStream()
00073 {
00074 open(iFileName, iRoot);
00075 }
00076
00077
00078
00079 XmlOFile::XmlOFile(const std::string& iFileName, std::ios::openmode iOpenMode):
00080 XmlOStream()
00081 {
00082 open(iFileName, iOpenMode);
00083 }
00084
00085
00086
00087 XmlOFile::XmlOFile(const std::string& iFileName, const std::string& iRoot):
00088 XmlOStream()
00089 {
00090 open(iFileName, iRoot);
00091 }
00092
00093
00094
00095 XmlOFile::~XmlOFile()
00096 {
00097 close();
00098 }
00099
00100
00101
00102 void XmlOFile::open(const char* iFilename, std::ios::openmode iOpenMode)
00103 {
00104 file_.open(iFilename, iOpenMode);
00105 root_ = "";
00106 clear(file_.rdstate());
00107 }
00108
00109
00110
00111 void XmlOFile::open(const char* iFilename, const char* iRoot)
00112 {
00113 file_.open(iFilename, std::ios::out | std::ios::trunc);
00114 root_ = iRoot;
00115 file_ << "<?xml version=\"1.0\"?>\n";
00116 file_ << "<" << root_ << ">\n";
00117 clear(file_.rdstate());
00118 }
00119
00120
00121
00122 void XmlOFile::open(const std::string& iFilename, std::ios::openmode iOpenMode)
00123 {
00124 open(iFilename.c_str(), iOpenMode);
00125 }
00126
00127
00128
00129 void XmlOFile::open(const std::string& iFilename, const std::string& iRoot)
00130 {
00131 open(iFilename.c_str(), iRoot.c_str());
00132 }
00133
00134
00135
00136 void XmlOFile::close()
00137 {
00138 if (file_.is_open() && !root_.empty())
00139 {
00140 file_ << "</" << root_ << ">\n";
00141 }
00142 file_.close();
00143 clear(file_.rdstate());
00144 }
00145
00146
00147
00148 bool XmlOFile::is_open()
00149 {
00150 return file_.is_open();
00151 }
00152
00153
00154
00155 #define LASS_IO_XML_O_FILE_INSERTOR( type__ )\
00156 XmlOFile& XmlOFile::operator<<( type__ iIn )\
00157 {\
00158 file_ << iIn;\
00159 clear(file_.rdstate());\
00160 return *this;\
00161 }
00162
00163 LASS_IO_XML_O_FILE_INSERTOR( char )
00164 LASS_IO_XML_O_FILE_INSERTOR( signed char )
00165 LASS_IO_XML_O_FILE_INSERTOR( unsigned char )
00166 LASS_IO_XML_O_FILE_INSERTOR( signed short )
00167 LASS_IO_XML_O_FILE_INSERTOR( unsigned short )
00168 LASS_IO_XML_O_FILE_INSERTOR( signed int )
00169 LASS_IO_XML_O_FILE_INSERTOR( unsigned int )
00170 LASS_IO_XML_O_FILE_INSERTOR( signed long )
00171 LASS_IO_XML_O_FILE_INSERTOR( unsigned long )
00172 LASS_IO_XML_O_FILE_INSERTOR( float )
00173 LASS_IO_XML_O_FILE_INSERTOR( double )
00174 LASS_IO_XML_O_FILE_INSERTOR( long double )
00175 LASS_IO_XML_O_FILE_INSERTOR( bool )
00176 LASS_IO_XML_O_FILE_INSERTOR( const void* )
00177 LASS_IO_XML_O_FILE_INSERTOR( const char* )
00178 LASS_IO_XML_O_FILE_INSERTOR( const std::string& )
00179
00180 XmlOFile& XmlOFile::operator<<( std::ostream& (*iIn) (std::ostream&) )
00181 {
00182 file_ << iIn;
00183 clear(file_.rdstate());
00184 return *this;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 }
00203
00204 }
00205
00206