-//
-// Convenience types.
-//
-typedef std::vector<Record*> RecordList;
-
-//
-// RecordListIter - Simplify iterating through a std::vector of records.
-//
-class RecordListIter {
- std::vector<Record*>::iterator RI; // Currect cursor
- std::vector<Record*>::iterator E; // End point
-
-public:
-
- //
- // Ctor.
- //
- RecordListIter(RecordList &RL)
- : RI(RL.begin()), E(RL.end())
- {}
-
-
- //
- // isMore - Return true if more records are available.
- //
- bool isMore() const { return RI != E; }
-
- //
- // next - Return the next record or NULL if none.
- //
- Record *next() { return isMore() ? *RI++ : NULL; }
-};
-
-//
-// DefListIter - Simplify iterating through a field which is a list of records.
-//
-struct DefListIter {
- ListInit *List; // List of DefInit
- unsigned N; // Number of elements in list
- unsigned i; // Current index in list
-
- //
- // Ctor - Lookup field and get list and length.
- //
- DefListIter(Record *R, const std::string &Name)
- : List(R->getValueAsListInit(Name)), N(List->getSize()), i(0)
- {}
-
- //
- // isMore - Return true if more records are available.
- //
- bool isMore() const { return i < N; }
-
- //
- // next - Return the next record or NULL if none.
- //
- Record *next() {
- if (isMore()) {
- if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i++))) {
- return DI->getDef();
- }
- }
- return NULL;
- }
-};
-
-//
-// Record sort by name function.
-//
-struct LessRecord {
- bool operator()(const Record *Rec1, const Record *Rec2) const {
- return Rec1->getName() < Rec2->getName();
- }
-};
-
-//
-// Record sort by field "Name" function.
-//
-struct LessRecordFieldName {
- bool operator()(const Record *Rec1, const Record *Rec2) const {
- return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
- }
-};
-