Decoded: OpenTTD (2003) v1.8 (2018) Source file: backup_type.hpp Line-by-line code walkthrough by MaiZure backup_type.hpp defines a Backup class to preserve variables Original code: https://github.com/MaiZure/OpenTTD-1.8/blob/master/src/core/backup_type.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 header for debug functions 16 - 17 * 18 * 19 * 20 * 21 * 22 Sets up a class template with a type parameter 23 BLOCK START - Backup, type-specific class to wrap a variable to back up its contents 24 * 25 * 26 * 27 * 28 * 29 * 30 Defines parameterized constructor using only an initial (original) value 31 - 32 * 33 * 34 * 35 * 36 * 37 * 38 * 39 Sets up a template with a type parameter for the new value 40 Defines a parameterized constructor using both an old and new value 41 BLOCK START - Backup parameterized constructor 42 * 43 Replaces the old value 44 BLOCK END - Backup parameterized constructor 45 - 46 * 47 * 48 * 49 Defines a 50 BLOCK START - Backup destructor 51 * 52 If the original value is valid... 53 BLOCK START - Check restoration 54 * 55 * 56 Output debug information 57 Restore the backed up value 58 BLOCK END - Check restoration 59 BLOCK END - Backup destructor 60 - 61 * 62 * 63 * 64 * 65 Defines IsValid with no arguments 66 BLOCK START - Backup::IsValid, checks state of the backup 67 Return the value of the 'valid' member 68 BLOCK END - Backup::IsValid 69 - 70 * 71 * 72 * 73 * 74 Defines Backup::GetOriginalValue with no arguments 75 BLOCK START - Backup::GetOriginalValue, returns the backup 76 Checks if the original value is actually valid 77 Returns the original value that was backed up 78 BLOCK END - Backup::GetOriginalValue 79 - 80 * 81 * 82 * 83 * 84 * 85 Sets up a template with a type name 86 Defines Backup::Change with one argument: a value of input type 87 BLOCK START - Backup::Change, changes the backup 88 * 89 Check if the backup is valid... 90 So we can update the value pointer knowing it's backed up 91 BLOCK END - Backup::Change 92 - 93 * 94 * 95 * 96 Defines Backup::Revert with no arguments 97 BLOCK START - Backup::Revert, matches the current to the backup 98 Check that the backup is valid 99 Restore the backed up value 100 BLOCK END - Backup::Revert 101 - 102 * 103 * 104 * 105 Defines Backup::Trash 106 BLOCK START - Backup::Trash, gets rid of the backup 107 Check that the backup is valid 108 Invalidate the backup 109 BLOCK END - Backup::Trash 110 - 111 * 112 * 113 * 114 Defines Backup::Restore 115 BLOCK START - Backup::Restore, fully restores the backup 116 Restore the original backup valid 117 Get rid of the backup now that it's restored 118 BLOCK END - Backup::Restore 119 - 120 * 121 * 122 * 123 * 124 Defines Backup::Update 125 BLOCK START - Backup::Update, changes the backed up value 126 Check that the backup is valid 127 Backup a new value 128 BLOCK END - Backup::Update 129 - 130 * 131 * 132 * 133 * 134 Defines Backup::Verify 135 BLOCK START - Backup::Verify, checks that current and backup match 136 Check that the backup is valid 137 Check that the current and backup values match 138 BLOCK END - Backup::Verify 139 - 140 Begins the private section, which holds the data 141 Declares a reference to the original value location 142 Declares a flag indicating if the value is currently valid 143 Declares a local value to back up 144 - 145 Declares a debug output file name 146 Declares a debug ouptut file line number 147 BLOCK END - Backup 148 - 149 Header guard end