Software Engineering Home
Sorting a Set of Coordinates : Code Sample

User code:

....


// A functor class to customise the PDBOrder functor so that it 
// works on a user defined Atom class.

class PDBAtomOrder
{ 
public:
 
    
    // Returns true if 1st Atom is `less than' 2nd Atom
    
    bool operator()( const Atom& atom1, const  Atom& atom2 )
    { 
    	PDBOrder p;
    	return p( atom1->GetId(), atom2->GetId() );
    }
};


// Create container of Atom objects

vector<Atom> atoms = pdbReader->GetAtoms();

// Sort Atoms into PDB order in place

sort( atoms.begin(), atoms.end(), AtomPDBOrder );

BTL code:



// A functor class that can be used to sort on a PDB type 
// atom id. key

class PDBOrder
{
public:

    
    // Returns true if 1st string is `less than' 
    // the 2nd string
    
    bool operator()( const string& atomId1, 
                     const string& atomId2 );
};


Back Back