Decoded: OpenTTD (2003) v1.8 (2018) Source file: mem_func.hpp Line-by-line code walkthrough by MaiZure mem_func.hpp defines type-safe memory movement functions Original code: https://github.com/MaiZure/OpenTTD-1.8/blob/master/src/core/mem_func.hpp 1 COMMENT (*) 2 BLANK (-) 3 * 4 * 5 * 6 * 7 * 8 * 9 - 10 * 11 - 12 Header guard 13 Header guard 14 - 15 Includes the OpenTTD math function header 16 - 17 * 18 * 19 * 20 * 21 * 22 * 23 * 24 Sets up a function template with one type parameter 25 Defines MemCpyT with three arguments: a destination memory address, a source memory address, and a element count 26 BLOCK START - MemCpyT, generates type-safe memcpy functions 27 Calls memcpy with the passed arguments after converting elements to bytes 28 BLOCK END - MemCpyT 29 - 30 * 31 * 32 * 33 * 34 * 35 * 36 * 37 Sets up a function template with one type parameter 38 Defines MemMoveT with three arguments: destination, source, and element count 39 BLOCK START - MemMoveT, generates type-safe memmove functions 40 Calls memmove passing the input arguments and converting elements to bytes 41 BLOCK END - MemMoveT 42 - 43 * 44 * 45 * 46 * 47 * 48 * 49 * 50 Sets up a function template with one type parameter 51 Defines MemSetT with three arguments: a destination, a value, and an element count 52 BLOCK START - MemSetT, generates type-safe memset functions 53 Calls memset with the passed arguments after converting elements to bytes 54 BLOCK END - MemSetT 55 - 56 * 57 * 58 * 59 * 60 * 61 * 62 * 63 * 64 Sets up a function template with one type parameter 65 Defines MemCmpT with three arguments: memory buffer 1, memory buffer 2, and an element count 66 BLOCK START - MemCmpT, generates type-safe functions for memcmp 67 Calls memcmp with the passed arguments after converting elements to bytes 68 BLOCK END - MemCmpT 69 - 70 * 71 * 72 * 73 * 74 * 75 * 76 * 77 * 78 Sets up a function template with one type parameter 79 Defines MemReverseT with two arguments: starting and ending pointers 80 BLOCK START - MemReverseT, reverses a section of memory one object at a type 81 Checks that both pointers aren't NULL 82 Checks that the first pointer is earlier than the second 83 - 84 Being loop to swap all elements 85 Swap the values of the objects under both pointers 86 Increment the first, decrement the second, (size of T) and continue loop if they haven't crossed 87 BLOCK END - MemReverseT 88 - 89 * 90 * 91 * 92 * 93 * 94 * 95 Sets up a function template with one type parameter 96 Defines MemReverseT with two arguments, a pointer and an element count 97 BLOCK START - MemReverseT, reverses a section of memory one object at a type -- now based on element count 98 Checks that the pointer isn't NULL 99 - 100 Passes arguments to the MemReverseT with the two pointer signature 101 BLOCK END - MemReverseT 102 - 103 Header guard end