Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
UpdateReferences tweaked
Browse files Browse the repository at this point in the history
  Tries to free up more memory while running
Added ValidateDict(Elements, Target) to cint
  Convenience function to determine if all formIDS in the dict's keys / values are valid for the target
  Supports nested dicts, tuples, lists
  • Loading branch information
waruddar committed Sep 11, 2011
1 parent 56d4f00 commit a081453
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
19 changes: 13 additions & 6 deletions CBash/CBash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,18 +1560,25 @@ CPPDLLEXTERN SINT32 UpdateReferences(ModFile *ModID, Record *RecordID, FORMIDARR
std::map<FORMID, std::vector<Record *> > formID_users;
RecordFormIDMapper mapper(formID_users, ModID->FormIDHandler, ModID->Parent->Expanders);
ModID->VisitAllRecords(mapper);
UINT32 OldFormID = 0, NewFormID = 0;
RecordReader reader(ModID);
Record *curRecord;
for(UINT32 ListIndex = 0; ListIndex < ArraySize; ++ListIndex)
{
//Sanity check.
if(OldFormIDs[ListIndex] == NewFormIDs[ListIndex])
OldFormID = OldFormIDs[ListIndex];
NewFormID = NewFormIDs[ListIndex];
if(OldFormID == NewFormID)
continue;
FormIDSwapper swapper(OldFormIDs[ListIndex], NewFormIDs[ListIndex], ModID->FormIDHandler);
std::vector<Record *> &users = formID_users[OldFormIDs[ListIndex]];
FormIDSwapper swapper(OldFormID, NewFormID, ModID->FormIDHandler);
std::vector<Record *> &users = formID_users[OldFormID];
for(UINT32 ListX2Index = 0; ListX2Index < users.size(); ++ListX2Index)
{
users[ListX2Index]->VisitFormIDs(swapper);
users[ListX2Index]->IsChanged(true);
ModID->Parent->changed_records.insert(users[ListX2Index]);
curRecord = users[ListX2Index];
reader.Accept(curRecord);
curRecord->VisitFormIDs(swapper);
curRecord->IsChanged(true);
ModID->Parent->changed_records.insert(curRecord);
}
Changes[ListIndex] = swapper.GetCount();
count += swapper.GetCount();
Expand Down
4 changes: 4 additions & 0 deletions CBash/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,10 @@ bool RecordFormIDMapper::Accept(Record *&curRecord)
mapper.curRecord = curRecord;
stop = curRecord->VisitFormIDs(mapper);

//If the record was read, but not changed, unload it again
if(reader.GetResult() && !curRecord->IsChanged())
curRecord->Unload();

return stop;
}

Expand Down
Binary file modified release/CBash.dll
Binary file not shown.
32 changes: 30 additions & 2 deletions release/cint-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,9 @@ def GetShortMGEFCode(self, target):
return self.mgefCode.GetShortMGEFCode(target)

def ValidateList(Elements, Target):
"""Convenience function to ensure that a list of values is valid for the destination.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the list are valid."""
"""Convenience function to ensure that a tuple/list of values is valid for the destination.
Supports nested tuple/list values.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the tuple/list are valid."""
isValid = True
for element in Elements:
if not isValid: return isValid
Expand All @@ -1225,6 +1226,33 @@ def ValidateList(Elements, Target):
isValid = ValidateList(element, Target)
return isValid

def ValidateDict(Elements, Target):
"""Convenience function to ensure that a dict is valid for the destination.
Supports nested dictionaries, and tuple/list values.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the dict are valid."""
isValid = True
for key, value in Elements.iteritems():
if isinstance(key, (FormID, ActorValue, MGEFCode)):
isValid = key.Validate(Target)
if not isValid: return isValid

if isinstance(value, (FormID, ActorValue, MGEFCode)):
isValid = value.Validate(Target)
if not isValid: return isValid

if isinstance(key, (tuple, list)):
isValid = ValidateList(key, Target)
if not isValid: return isValid

if isinstance(value, (tuple, list)):
isValid = ValidateList(value, Target)
if not isValid: return isValid

if isinstance(value, dict):
isValid = ValidateDict(value, Target)
if not isValid: return isValid
return isValid

def getattr_deep(obj, attr):
return reduce(getattr, attr.split('.'), obj)

Expand Down
32 changes: 30 additions & 2 deletions release/cint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,9 @@ def GetShortMGEFCode(self, target):
return self.mgefCode.GetShortMGEFCode(target)

def ValidateList(Elements, Target):
"""Convenience function to ensure that a list of values is valid for the destination.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the list are valid."""
"""Convenience function to ensure that a tuple/list of values is valid for the destination.
Supports nested tuple/list values.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the tuple/list are valid."""
isValid = True
for element in Elements:
if not isValid: return isValid
Expand All @@ -1225,6 +1226,33 @@ def ValidateList(Elements, Target):
isValid = ValidateList(element, Target)
return isValid

def ValidateDict(Elements, Target):
"""Convenience function to ensure that a dict is valid for the destination.
Supports nested dictionaries, and tuple/list values.
Returns true if all of the FormIDs/ActorValues/MGEFCodes in the dict are valid."""
isValid = True
for key, value in Elements.iteritems():
if isinstance(key, (FormID, ActorValue, MGEFCode)):
isValid = key.Validate(Target)
if not isValid: return isValid

if isinstance(value, (FormID, ActorValue, MGEFCode)):
isValid = value.Validate(Target)
if not isValid: return isValid

if isinstance(key, (tuple, list)):
isValid = ValidateList(key, Target)
if not isValid: return isValid

if isinstance(value, (tuple, list)):
isValid = ValidateList(value, Target)
if not isValid: return isValid

if isinstance(value, dict):
isValid = ValidateDict(value, Target)
if not isValid: return isValid
return isValid

def getattr_deep(obj, attr):
return reduce(getattr, attr.split('.'), obj)

Expand Down

0 comments on commit a081453

Please sign in to comment.