#define INCLUDED_IDATASTREAM_H
#include <cstddef>
+#include <iostream>
class StreamBase
{
typedef int offset_type;
typedef std::size_t position_type;
-enum seekdir
-{
- beg,
- cur,
- end,
-};
+using seekdir = std::ios_base::seekdir;
+static const auto cur = std::ios_base::cur;
+static const auto beg = std::ios_base::beg;
+static const auto end = std::ios_base::end;
/// \brief Sets the current \p position of the stream relative to the start.
virtual position_type seek( position_type position ) = 0;
#include "memory/allocator.h"
template<typename Element, typename Allocator = DefaultAllocator<Element> >
using Array = std::vector<Element, Allocator>;
-/// \todo replace Array<char> with std::string
#if 0
#include <cstddef>
if ( path != 0 && !string_empty( path ) ) {
ASSERT_MESSAGE( path_is_absolute( path ), "file_dialog_show: path not absolute: " << makeQuoted( path ) );
- Array<char> new_path( strlen( path ) + 1 );
+ std::string new_path(path);
+ std::replace(new_path.begin(), new_path.end(), '/', G_DIR_SEPARATOR);
+ if ( !new_path.empty() && new_path.back() == G_DIR_SEPARATOR )
+ new_path.pop_back();
- // copy path, replacing dir separators as appropriate
- Array<char>::iterator w = new_path.begin();
- for ( const char* r = path; *r != '\0'; ++r )
- {
- *w++ = ( *r == '/' ) ? G_DIR_SEPARATOR : *r;
- }
- // remove separator from end of path if required
- if ( *( w - 1 ) == G_DIR_SEPARATOR ) {
- --w;
- }
- // terminate string
- *w = '\0';
-
- gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.data() );
+ gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.c_str() );
}
// we should add all important paths as shortcut folder...
istream_read_int32_le( m_istream );
unsigned int position = istream_read_int32_le( m_istream );
- Array<char> filename( namelength + 1 );
- m_istream.read( reinterpret_cast<FileInputStream::byte_type*>( filename.data() ), namelength );
- filename[namelength] = '\0';
+ std::string filename( namelength, ' ' );
+ if ( namelength > 0 )
+ m_istream.read( reinterpret_cast<FileInputStream::byte_type*>( &filename[0] ), namelength );
m_istream.seek( extras + comment, FileInputStream::cur );
- if ( path_is_directory( filename.data() ) ) {
- m_filesystem[filename.data()] = 0;
+ if ( path_is_directory( filename.c_str() ) ) {
+ m_filesystem[filename.c_str()] = 0;
}
else
{
- ZipFileSystem::entry_type& file = m_filesystem[filename.data()];
+ ZipFileSystem::entry_type& file = m_filesystem[filename.c_str()];
if ( !file.is_directory() ) {
- globalOutputStream() << "Warning: zip archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( filename.data() ) << "\n";
+ globalOutputStream() << "Warning: zip archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( filename.c_str() ) << "\n";
}
else
{
}
bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){
- Array<char> tmpName( filename, filename + strlen( filename ) + 1 + 3 );
- *( tmpName.end() - 4 ) = 'T';
- *( tmpName.end() - 3 ) = 'M';
- *( tmpName.end() - 2 ) = 'P';
- *( tmpName.end() - 1 ) = '\0';
+ std::string tmpName( filename );
+ tmpName += "TMP";
- return Preferences_Save( preferences, tmpName.data() )
+ return Preferences_Save( preferences, tmpName.c_str() )
&& ( !file_exists( filename ) || file_remove( filename ) )
- && file_move( tmpName.data(), filename );
+ && file_move( tmpName.c_str(), filename );
}
GLint log_length = 0;
glGetObjectParameterivARB( object, GL_OBJECT_INFO_LOG_LENGTH_ARB, &log_length );
- Array<char> log( log_length );
- glGetInfoLogARB( object, log_length, &log_length, log.data() );
+
+ std::string log( log_length, ' ' );
+ if ( !log.empty() )
+ glGetInfoLogARB( object, log_length, &log_length, &log[0] );
globalErrorStream() << StringRange( log.data(), log.data() + log_length ) << "\n";
}