Permalink
Browse files

Switch from std::string to String/ByteString in most of the code

Also switch SimulationData from weird arrays to std::vector
  • Loading branch information...
mniip committed Apr 30, 2018
1 parent 4912674 commit ff27d694242c2de2d85ccfbed953186bb38a0628
Showing with 1,838 additions and 1,714 deletions.
  1. +8 −8 src/Format.cpp
  2. +23 −9 src/Format.h
  3. +0 −2 src/Misc.h
  4. +4 −4 src/Platform.cpp
  5. +3 −3 src/Platform.h
  6. +2 −3 src/PowderToy.h
  7. +12 −13 src/PowderToyRenderer.cpp
  8. +37 −37 src/PowderToySDL.cpp
  9. +5 −5 src/Update.cpp
  10. +209 −176 src/client/Client.cpp
  11. +56 −52 src/client/Client.h
  12. +1 −1 src/client/ClientListener.h
  13. +8 −8 src/client/Download.cpp
  14. +11 −11 src/client/Download.h
  15. +12 −23 src/client/GameSave.cpp
  16. +8 −8 src/client/GameSave.h
  17. +12 −13 src/client/HTTP.cpp
  18. +4 −4 src/client/HTTP.h
  19. +8 −8 src/client/SaveFile.cpp
  20. +11 −11 src/client/SaveFile.h
  21. +13 −13 src/client/SaveInfo.cpp
  22. +15 −15 src/client/SaveInfo.h
  23. +5 −5 src/client/User.h
  24. +6 −6 src/client/UserInfo.h
  25. +7 −7 src/client/requestbroker/APIRequest.cpp
  26. +4 −4 src/client/requestbroker/APIRequest.h
  27. +3 −3 src/client/requestbroker/ImageRequest.cpp
  28. +2 −2 src/client/requestbroker/ImageRequest.h
  29. +5 −6 src/client/requestbroker/RequestBroker.cpp
  30. +4 −4 src/client/requestbroker/RequestBroker.h
  31. +7 −7 src/client/requestbroker/WebRequest.cpp
  32. +4 −4 src/client/requestbroker/WebRequest.h
  33. +132 −0 src/common/String.cpp
  34. +51 −6 src/common/String.h
  35. +8 −8 src/debug/DebugLines.cpp
  36. +3 −4 src/debug/DebugParts.cpp
  37. +3 −3 src/debug/ElementPopulation.cpp
  38. +2 −3 src/debug/ParticleDebug.cpp
  39. +3 −4 src/graphics/DrawMethodsDef.inc
  40. +33 −21 src/graphics/Graphics.cpp
  41. +14 −15 src/graphics/Graphics.h
  42. +6 −10 src/graphics/OpenGLDrawMethods.inl
  43. +7 −11 src/graphics/RasterDrawMethods.inl
  44. +9 −9 src/graphics/Renderer.cpp
  45. +4 −5 src/graphics/Renderer.h
  46. +2 −2 src/gui/colourpicker/ColourPickerActivity.cpp
  47. +1 −1 src/gui/colourpicker/ColourPickerActivity.h
  48. +5 −5 src/gui/console/ConsoleCommand.h
  49. +2 −2 src/gui/console/ConsoleController.cpp
  50. +3 −3 src/gui/console/ConsoleController.h
  51. +2 −2 src/gui/console/ConsoleModel.cpp
  52. +3 −3 src/gui/dialogues/ConfirmPrompt.cpp
  53. +4 −4 src/gui/dialogues/ConfirmPrompt.h
  54. +2 −2 src/gui/dialogues/ErrorMessage.cpp
  55. +2 −2 src/gui/dialogues/ErrorMessage.h
  56. +1 −1 src/gui/dialogues/InformationMessage.cpp
  57. +1 −1 src/gui/dialogues/InformationMessage.h
  58. +4 −4 src/gui/dialogues/LegacyDialogues.h
  59. +6 −6 src/gui/dialogues/TextPrompt.cpp
  60. +3 −3 src/gui/dialogues/TextPrompt.h
  61. +9 −8 src/gui/elementsearch/ElementSearchActivity.cpp
  62. +3 −4 src/gui/elementsearch/ElementSearchActivity.h
  63. +16 −17 src/gui/filebrowser/FileBrowserActivity.cpp
  64. +5 −5 src/gui/filebrowser/FileBrowserActivity.h
  65. +17 −18 src/gui/font/FontEditor.cpp
  66. +7 −7 src/gui/font/FontEditor.h
  67. +1 −1 src/gui/game/DecorationTool.h
  68. +6 −6 src/gui/game/Favorite.cpp
  69. +6 −6 src/gui/game/Favorite.h
  70. +26 −26 src/gui/game/GameController.cpp
  71. +7 −7 src/gui/game/GameController.h
  72. +18 −18 src/gui/game/GameModel.cpp
  73. +11 −11 src/gui/game/GameModel.h
  74. +4 −5 src/gui/game/GameModelException.h
  75. +63 −64 src/gui/game/GameView.cpp
  76. +8 −8 src/gui/game/GameView.h
  77. +9 −8 src/gui/game/Menu.h
  78. +3 −3 src/gui/game/Notification.h
  79. +19 −20 src/gui/game/PropertyTool.cpp
  80. +8 −8 src/gui/game/QuickOption.h
  81. +2 −2 src/gui/game/RenderPreset.h
  82. +6 −6 src/gui/game/SignTool.cpp
  83. +8 −8 src/gui/game/Tool.cpp
  84. +14 −15 src/gui/game/Tool.h
  85. +2 −2 src/gui/game/ToolButton.cpp
  86. +2 −2 src/gui/game/ToolButton.h
  87. +1 −1 src/gui/interface/AvatarButton.cpp
  88. +5 −5 src/gui/interface/AvatarButton.h
  89. +5 −5 src/gui/interface/Button.cpp
  90. +9 −9 src/gui/interface/Button.h
  91. +3 −3 src/gui/interface/Checkbox.cpp
  92. +6 −6 src/gui/interface/Checkbox.h
  93. +2 −2 src/gui/interface/Component.cpp
  94. +2 −2 src/gui/interface/Component.h
  95. +1 −1 src/gui/interface/ContextMenu.cpp
  96. +3 −3 src/gui/interface/ContextMenu.h
  97. +2 −2 src/gui/interface/CopyTextButton.cpp
  98. +1 −1 src/gui/interface/CopyTextButton.h
  99. +9 −9 src/gui/interface/DropDown.cpp
  100. +7 −7 src/gui/interface/DropDown.h
  101. +30 −31 src/gui/interface/Label.cpp
  102. +12 −12 src/gui/interface/Label.h
  103. +5 −5 src/gui/interface/ProgressBar.cpp
  104. +4 −4 src/gui/interface/ProgressBar.h
  105. +15 −15 src/gui/interface/RichLabel.cpp
  106. +8 −8 src/gui/interface/RichLabel.h
  107. +14 −14 src/gui/interface/SaveButton.cpp
  108. +5 −5 src/gui/interface/SaveButton.h
  109. +33 −33 src/gui/interface/Textbox.cpp
  110. +7 −7 src/gui/interface/Textbox.h
  111. +2 −2 src/gui/interface/Window.h
  112. +8 −10 src/gui/localbrowser/LocalBrowserController.cpp
  113. +1 −1 src/gui/localbrowser/LocalBrowserController.h
  114. +2 −2 src/gui/localbrowser/LocalBrowserModel.cpp
  115. +6 −6 src/gui/localbrowser/LocalBrowserModel.h
  116. +4 −5 src/gui/localbrowser/LocalBrowserModelException.h
  117. +4 −5 src/gui/localbrowser/LocalBrowserView.cpp
  118. +1 −1 src/gui/login/LoginController.cpp
  119. +2 −2 src/gui/login/LoginController.h
  120. +2 −2 src/gui/login/LoginModel.cpp
  121. +4 −4 src/gui/login/LoginModel.h
  122. +2 −2 src/gui/login/LoginView.cpp
  123. +17 −17 src/gui/options/OptionsView.cpp
  124. +5 −5 src/gui/preview/Comment.h
  125. +4 −5 src/gui/preview/PreviewController.cpp
  126. +2 −2 src/gui/preview/PreviewController.h
  127. +15 −15 src/gui/preview/PreviewModel.cpp
  128. +4 −4 src/gui/preview/PreviewModelException.h
  129. +13 −14 src/gui/preview/PreviewView.cpp
  130. +5 −5 src/gui/preview/PreviewView.h
  131. +3 −3 src/gui/profile/ProfileActivity.cpp
  132. +3 −3 src/gui/profile/ProfileActivity.h
  133. +2 −2 src/gui/render/RenderView.cpp
  134. +2 −2 src/gui/render/RenderView.h
  135. +5 −5 src/gui/save/LocalSaveActivity.cpp
  136. +1 −1 src/gui/save/LocalSaveActivity.h
  137. +6 −6 src/gui/save/ServerSaveActivity.cpp
  138. +1 −1 src/gui/save/ServerSaveActivity.h
  139. +16 −17 src/gui/search/SearchController.cpp
  140. +3 −3 src/gui/search/SearchController.h
  141. +5 −5 src/gui/search/SearchModel.cpp
  142. +11 −11 src/gui/search/SearchModel.h
  143. +11 −13 src/gui/search/SearchView.cpp
  144. +1 −1 src/gui/search/SearchView.h
  145. +2 −2 src/gui/tags/TagsController.cpp
  146. +2 −2 src/gui/tags/TagsController.h
  147. +6 −6 src/gui/tags/TagsModel.cpp
  148. +3 −3 src/gui/tags/TagsModel.h
  149. +4 −4 src/gui/tags/TagsModelException.h
  150. +8 −8 src/gui/tags/TagsView.cpp
  151. +4 −5 src/gui/update/UpdateActivity.cpp
  152. +5 −6 src/lua/CommandInterface.cpp
  153. +7 −7 src/lua/CommandInterface.h
  154. +34 −35 src/lua/LegacyLuaAPI.cpp
  155. +5 −5 src/lua/LuaButton.cpp
  156. +4 −4 src/lua/LuaCheckbox.cpp
  157. +3 −3 src/lua/LuaLabel.cpp
  158. +3 −3 src/lua/LuaProgressBar.cpp
  159. +2 −2 src/lua/LuaScriptHelper.h
  160. +89 −90 src/lua/LuaScriptInterface.cpp
  161. +3 −3 src/lua/LuaScriptInterface.h
  162. +1 −1 src/lua/LuaSlider.cpp
  163. +5 −5 src/lua/LuaTextbox.cpp
  164. +14 −14 src/lua/LuaWindow.cpp
  165. +8 −9 src/lua/TPTSTypes.cpp
  166. +10 −10 src/lua/TPTSTypes.h
  167. +46 −60 src/lua/TPTScriptInterface.cpp
  168. +12 −12 src/lua/TPTScriptInterface.h
  169. +0 −2 src/powdertoyjava/PowderToyJava.cpp
  170. +2 −2 src/simulation/GOLMenu.h
  171. +2 −2 src/simulation/MenuSection.h
  172. +5 −6 src/simulation/Sign.cpp
  173. +6 −6 src/simulation/Sign.h
  174. +7 −29 src/simulation/Simulation.cpp
  175. +7 −7 src/simulation/Simulation.h
  176. +12 −36 src/simulation/SimulationData.cpp
  177. +7 −6 src/simulation/SimulationData.h
  178. +0 −1 src/simulation/StorageClasses.h
  179. +3 −3 src/simulation/StructProperty.h
  180. +4 −3 src/simulation/WallType.h
  181. +3 −3 src/simulation/elements/Element.h
  182. +2 −4 src/simulation/elements/LIFE.cpp
  183. +3 −3 src/simulation/simtools/SimTool.h
  184. +12 −12 src/tasks/Task.cpp
  185. +9 −9 src/tasks/Task.h
  186. +4 −5 src/tasks/TaskWindow.cpp
  187. +3 −4 src/tasks/TaskWindow.h
@@ -1,6 +1,6 @@
#include <ctime>
#include <string>
#include "common/String.h"
#include <stdexcept>
#include <iostream>
#include <iterator>
@@ -9,7 +9,7 @@
#include "Format.h"
#include "graphics/Graphics.h"
std::string format::URLEncode(std::string source)
ByteString format::URLEncode(ByteString source)
{
char * src = (char *)source.c_str();
char * dst = new char[(source.length()*3)+2];
@@ -33,23 +33,23 @@ std::string format::URLEncode(std::string source)
}
*d = 0;
std::string finalString(dst);
ByteString finalString(dst);
delete[] dst;
return finalString;
}
std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
ByteString format::UnixtimeToDate(time_t unixtime, ByteString dateFormat)
{
struct tm * timeData;
char buffer[128];
timeData = localtime(&unixtime);
strftime(buffer, 128, dateFormat.c_str(), timeData);
return std::string(buffer);
return ByteString(buffer);
}
std::string format::UnixtimeToDateMini(time_t unixtime)
ByteString format::UnixtimeToDateMini(time_t unixtime)
{
time_t currentTime = time(NULL);
struct tm currentTimeData = *localtime(&currentTime);
@@ -69,7 +69,7 @@ std::string format::UnixtimeToDateMini(time_t unixtime)
}
}
std::string format::CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric)
String format::CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric)
{
for (size_t i = 0; i < dirtyString.size(); i++)
{
@@ -226,7 +226,7 @@ struct PNGChunk
//char[4] CRC();
PNGChunk(int length, std::string name)
PNGChunk(int length, ByteString name)
{
if (name.length()!=4)
throw std::runtime_error("Invalid chunk name");
@@ -1,6 +1,6 @@
#pragma once
#include <sstream>
#include "common/String.h"
#include <vector>
class VideoBuffer;
@@ -9,24 +9,38 @@ namespace format
{
const static char hex[] = "0123456789ABCDEF";
template <typename T> std::string NumberToString(T number)
template <typename T> ByteString NumberToByteString(T number)
{
std::stringstream ss;
ByteString::Stream ss;
ss << number;
return ss.str();
}
template <typename T> T StringToNumber(const std::string & text)
template <typename T> String NumberToString(T number)
{
std::stringstream ss(text);
String::Stream ss;
ss << number;
return ss.str();
}
template <typename T> T ByteStringToNumber(const ByteString & text)
{
ByteString::Stream ss(text);
T number;
return (ss >> number)?number:0;
}
template <typename T> T StringToNumber(const String & text)
{
String::Stream ss(text);
T number;
return (ss >> number)?number:0;
}
std::string URLEncode(std::string value);
std::string UnixtimeToDate(time_t unixtime, std::string dateFomat = "%d %b %Y");
std::string UnixtimeToDateMini(time_t unixtime);
std::string CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
ByteString URLEncode(ByteString value);
ByteString UnixtimeToDate(time_t unixtime, ByteString dateFomat = "%d %b %Y");
ByteString UnixtimeToDateMini(time_t unixtime);
String CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
std::vector<char> VideoBufferToPNG(const VideoBuffer & vidBuf);
std::vector<char> VideoBufferToBMP(const VideoBuffer & vidBuf);
std::vector<char> VideoBufferToPPM(const VideoBuffer & vidBuf);
@@ -2,8 +2,6 @@
#define UTILS_H
#include <cstdio>
#include <cstdlib>
#include <string>
#include <sstream>
#include <vector>
//Linear interpolation
@@ -20,9 +20,9 @@
namespace Platform
{
std::string ExecutableName()
ByteString ExecutableName()
{
std::string ret;
ByteString ret;
#if defined(WIN)
char *name = (char *)malloc(64);
DWORD max = 64, res;
@@ -73,7 +73,7 @@ std::string ExecutableName()
void DoRestart()
{
std::string exename = ExecutableName();
ByteString exename = ExecutableName();
if (exename.length())
{
#ifdef WIN
@@ -85,7 +85,7 @@ void DoRestart()
exit(-1);
}
void OpenURI(std::string uri)
void OpenURI(ByteString uri)
{
#if defined(WIN)
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
@@ -1,14 +1,14 @@
#ifndef PLATFORM_H
#define PLATFORM_H
#include <string>
#include "common/String.h"
namespace Platform
{
std::string ExecutableName();
ByteString ExecutableName();
void DoRestart();
void OpenURI(std::string uri);
void OpenURI(ByteString uri);
void Millisleep(long int t);
long unsigned int GetTime();
@@ -1,9 +1,8 @@
#pragma once
#include <string>
void EngineProcess();
void ClipboardPush(std::string text);
std::string ClipboardPull();
void ClipboardPush(ByteString text);
ByteString ClipboardPull();
int GetModifiers();
bool LoadWindowPosition(int scale);
void SetCursorEnabled(int enabled);
@@ -2,11 +2,10 @@
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <vector>
#include "common/String.h"
#include "Config.h"
#include "Format.h"
#include "gui/interface/Engine.h"
@@ -18,16 +17,16 @@
void EngineProcess() {}
void ClipboardPush(std::string) {}
std::string ClipboardPull() { return ""; }
void ClipboardPush(ByteString) {}
ByteString ClipboardPull() { return ""; }
int GetModifiers() { return 0; }
void SetCursorEnabled(int enabled) {}
unsigned int GetTicks() { return 0; }
void readFile(std::string filename, std::vector<char> & storage)
void readFile(ByteString filename, std::vector<char> & storage)
{
std::ifstream fileStream;
fileStream.open(std::string(filename).c_str(), std::ios::binary);
fileStream.open(filename.c_str(), std::ios::binary);
if(fileStream.is_open())
{
fileStream.seekg(0, std::ios::end);
@@ -45,10 +44,10 @@ void readFile(std::string filename, std::vector<char> & storage)
}
}
void writeFile(std::string filename, std::vector<char> & fileData)
void writeFile(ByteString filename, std::vector<char> & fileData)
{
std::ofstream fileStream;
fileStream.open(std::string(filename).c_str(), std::ios::binary);
fileStream.open(filename.c_str(), std::ios::binary);
if(fileStream.is_open())
{
fileStream.write(&fileData[0], fileData.size());
@@ -59,13 +58,13 @@ void writeFile(std::string filename, std::vector<char> & fileData)
int main(int argc, char *argv[])
{
ui::Engine * engine;
std::string outputPrefix, inputFilename;
ByteString outputPrefix, inputFilename;
std::vector<char> inputFile;
std::string ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
ByteString ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
std::vector<char> ppmFile, ptiFile, ptiSmallFile, pngFile, pngSmallFile;
inputFilename = std::string(argv[1]);
outputPrefix = std::string(argv[2]);
inputFilename = argv[1];
outputPrefix = argv[2];
ppmFilename = outputPrefix+".ppm";
ptiFilename = outputPrefix+".pti";
@@ -88,7 +87,7 @@ int main(int argc, char *argv[])
catch (ParseException e)
{
//Render the save again later or something? I don't know
if (e.what() == "Save from newer version")
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
throw e;
}
Oops, something went wrong.

0 comments on commit ff27d69

Please sign in to comment.