]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Convert Array<char> to std::string
authorMattia Basaglia <mattia.basaglia@gmail.com>
Tue, 21 Jul 2015 05:48:37 +0000 (07:48 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Tue, 21 Jul 2015 05:48:37 +0000 (07:48 +0200)
include/idatastream.h
libs/container/array.h
libs/gtkutil/filechooser.cpp
plugins/archivezip/archive.cpp
radiant/preferences.cpp
radiant/renderstate.cpp

index 674c9fa98fb5df2037a706cb6b78dc74743d40fb..c15991c67a297f2a362e585c4e904c23ffb2592a 100644 (file)
@@ -23,6 +23,7 @@
 #define INCLUDED_IDATASTREAM_H
 
 #include <cstddef>
+#include <iostream>
 
 class StreamBase
 {
@@ -55,12 +56,10 @@ public:
 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;
index 57d2f6b0b73b22a3dcf9e4bb7b24ca6e1513e5d2..e2889b372b4435ceb3becad4e050acc8ba27df5d 100644 (file)
@@ -27,7 +27,6 @@
 #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>
index a47019f151024764d175b4dd4311cfea80b98b80..55130efdfe65fb141a150a715150a562480ce670 100644 (file)
@@ -170,22 +170,12 @@ const char* file_dialog_show( GtkWidget* parent, bool open, const char* title, c
        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...
index 1136a5c0591febd24db637d76cf2f80d0b6b8083..2c29a1397360619e5cf001312d7d30af0816f65a 100644 (file)
@@ -148,20 +148,20 @@ bool read_record(){
        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
                {
index 1e2251d3e644e3871f75d2f4f1d3afa1fc3539ff..b5a1ac5958d38ba108c4c76204a9bbdf88a08304 100644 (file)
@@ -215,15 +215,12 @@ bool Preferences_Save( PreferenceDictionary& preferences, const char* filename )
 }
 
 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 );
 }
 
 
index ede257409220ab10441ae02bc28127788b8d1e0b..a899e7ed4df9c7e4ba2fe9579e93243f52107af3 100644 (file)
@@ -129,8 +129,10 @@ void printShaderLog( GLhandleARB object ){
        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";
 }