1 module rip.io.interfaces; 2 3 import std.stdio; 4 5 /++ 6 + Base interface for format workers 7 + Can be used not only for Surface 8 + Example: 9 + ------------ 10 + FormatWorker!int loader = new ... 11 + int answer = 42; 12 + int question; 13 14 + loader.save(42, "output.txt"); 15 + question = loader.load("universe.txt") 16 + ------------ 17 +/ 18 interface FormatWorker(T) { 19 /++ 20 + Saves data to file 21 + Params: 22 + surface = input data 23 + name = file name 24 + Returns: 25 + input data for using in UFCS 26 + 27 +/ 28 T save(in T surface, in string name) const; 29 //ошибка должна выбивать исключение 30 31 /++ 32 + Loads data from file 33 + Params: 34 + filename = file name 35 + Returns: 36 + loaded data 37 +/ 38 T load(in string name) const; 39 40 /++ 41 + Decodes data from file 42 + Params: 43 + file = file 44 + Returns: 45 + decoded data from file 46 +/ 47 T decode(File file) const; 48 49 /++ 50 + Check file for header 51 + Params: 52 + file = file 53 + Returns: 54 + 'true' if file have header of this format 55 +/ 56 bool checkOnHeader(File file) const; 57 } 58 59 //этому шаблону здесь не место 60 mixin template colorsToFile() { 61 import std.stdio; 62 void toFile(RGBColor color) { 63 file.write( 64 color.red!char, 65 color.green!char, 66 color.blue!char); 67 } 68 69 /*surface.getPixelsRange().each!toFile;*/ 70 auto range = surface.getPixels(); 71 72 import std.algorithm; 73 /*each!toFile(range);*/ 74 //Бага? 75 //source/io/interfaces.d(25,16): Error: function declaration without return type. (Note that constructors are always named 'this') 76 //source/io/interfaces.d(25,23): Error: no identifier for declarator each!toFile(range) 77 }