Add Comparable? field to structs.csv
Generates operator== and operator!= for
structs with Comparable? ==1
MODIFY
generator/csv/structs.csv
generator/csv/structs.csv
-#Type,Structure,Index available?
-ldb,Parameters,
-ldb,Equipment,
-ldb,EventCommand,
-ldb,MoveCommand,
-ldb,Learning,1
-ldb,Actor,1
-ldb,Sound,0
-ldb,AnimationTiming,1
-ldb,AnimationCellData,1
-ldb,AnimationFrame,1
-ldb,Animation,1
-ldb,Attribute,1
-ldb,BattleCommand,1
-ldb,BattleCommands,0
-ldb,BattlerAnimationExtension,1
-ldb,BattlerAnimation,1
-ldb,BattlerAnimationData,1
-ldb,Chipset,1
-ldb,Class,1
-ldb,CommonEvent,1
-ldb,Skill,1
-ldb,ItemAnimation,1
-ldb,Item,1
-ldb,EnemyAction,1
-ldb,Enemy,1
-ldb,TroopMember,1
-ldb,TroopPageCondition,0
-ldb,TroopPage,1
-ldb,Troop,1
-ldb,Terrain,1
-ldb,State,1
-ldb,Terms,0
-ldb,Music,0
-ldb,TestBattler,1
-ldb,System,0
-ldb,Switch,1
-ldb,Variable,1
-ldb,Database,0
-lmu,EventPageCondition,0
-lmu,MoveRoute,0
-lmu,EventPage,1
-lmu,Event,1
-lmu,Map,0
-lsd,SaveTitle,0
-lsd,SaveSystem,0
-lsd,SaveScreen,0
-lsd,SavePicture,1
-lsd,SavePartyLocation,0
-lsd,SaveVehicleLocation,0
-lsd,SaveActor,1
-lsd,SaveInventory,0
-lsd,SaveTarget,1
-lsd,SaveEventCommands,1
-lsd,SaveEventData,0
-lsd,SaveMapEvent,1
-lsd,SaveMapInfo,0
-lsd,SaveCommonEvent,1
-lsd,Save,0
-lmt,Rect,
-lmt,Encounter,1
-lmt,MapInfo,1
-lmt,Start,0
-lmt,TreeMap,
+#Type,Structure,Index available?,Comparable?
+ldb,Parameters,,0
+ldb,Equipment,,0
+ldb,EventCommand,,0
+ldb,MoveCommand,,0
+ldb,Learning,1,0
+ldb,Actor,1,0
+ldb,Sound,0,0
+ldb,AnimationTiming,1,0
+ldb,AnimationCellData,1,0
+ldb,AnimationFrame,1,0
+ldb,Animation,1,0
+ldb,Attribute,1,0
+ldb,BattleCommand,1,0
+ldb,BattleCommands,0,0
+ldb,BattlerAnimationExtension,1,0
+ldb,BattlerAnimation,1,0
+ldb,BattlerAnimationData,1,0
+ldb,Chipset,1,0
+ldb,Class,1,0
+ldb,CommonEvent,1,0
+ldb,Skill,1,0
+ldb,ItemAnimation,1,0
+ldb,Item,1,0
+ldb,EnemyAction,1,0
+ldb,Enemy,1,0
+ldb,TroopMember,1,0
+ldb,TroopPageCondition,0,0
+ldb,TroopPage,1,0
+ldb,Troop,1,0
+ldb,Terrain,1,0
+ldb,State,1,0
+ldb,Terms,0,0
+ldb,Music,0,0
+ldb,TestBattler,1,0
+ldb,System,0,0
+ldb,Switch,1,0
+ldb,Variable,1,0
+ldb,Database,0,0
+lmu,EventPageCondition,0,0
+lmu,MoveRoute,0,0
+lmu,EventPage,1,0
+lmu,Event,1,0
+lmu,Map,0,0
+lsd,SaveTitle,0,0
+lsd,SaveSystem,0,0
+lsd,SaveScreen,0,0
+lsd,SavePicture,1,0
+lsd,SavePartyLocation,0,0
+lsd,SaveVehicleLocation,0,0
+lsd,SaveActor,1,0
+lsd,SaveInventory,0,0
+lsd,SaveTarget,1,0
+lsd,SaveEventCommands,1,0
+lsd,SaveEventData,0,0
+lsd,SaveMapEvent,1,0
+lsd,SaveMapInfo,0,0
+lsd,SaveCommonEvent,1,0
+lsd,Save,0,0
+lmt,Rect,,0
+lmt,Encounter,1,0
+lmt,MapInfo,1,0
+lmt,Start,0,0
+lmt,TreeMap,,0

MODIFY
generator/generate.py
generator/generate.py
@@ -215,7 +215,7 @@ def process_file(filename, namedtup):
return result
def get_structs(filename='structs.csv'):
- Struct = namedtuple("Struct", "name hasid")
+ Struct = namedtuple("Struct", "name hasid iscomparable")
result = process_file(filename, Struct)
@@ -225,7 +225,7 @@ def get_structs(filename='structs.csv'):
processed_result[k] = []
for elem in struct:
- elem = Struct(elem.name, bool(int(elem.hasid)) if elem.hasid else None)
+ elem = Struct(elem.name, bool(int(elem.hasid)) if elem.hasid else None, bool(int(elem.iscomparable)))
processed_result[k].append(elem)
return processed_result
@@ -341,7 +341,8 @@ def generate():
with open(filepath, 'w') as f:
f.write(rpg_header_tmpl.render(
struct_name=struct.name,
- has_id=struct.hasid
+ has_id=struct.hasid,
+ is_comparable=struct.iscomparable
))
if struct.name in flags:

MODIFY
generator/templates/rpg_header.tmpl
generator/templates/rpg_header.tmpl
@@ -83,6 +83,22 @@ namespace RPG {
{%- endif %}
{%- endfor %}
};
+ {%- if is_comparable %}
+
+ inline bool operator==(const {{ struct_name }}& l, const {{ struct_name }}& r) {
+ {%- for field in fields[struct_name]|field_is_used -%}
+ {% if loop.first %}
+ return
+ {%- else %}
+ &&
+ {%- endif %} l.{{ field.name }} == r.{{ field.name }} {%- if loop.last %};{%- endif %}
+ {%- endfor %}
+ }
+
+ inline bool operator!=(const {{ struct_name }}& l, const {{ struct_name }}& r) {
+ return !(l == r);
+ }
+ {%- endif %}
}
#endif

Add Comparable? field to structs.csv

Generates operator== and operator!= for
structs with Comparable? ==1