From d122e0084b45feee5f5722af74ae0539124e0c0e Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 23 May 2005 22:30:26 +0000 Subject: [PATCH] add sort_filename --- panda/src/egg/eggFilenameNode.h | 8 ++++++++ panda/src/egg/eggTextureCollection.cxx | 14 ++++++++++++++ panda/src/egg/eggTextureCollection.h | 1 + 3 files changed, 23 insertions(+) diff --git a/panda/src/egg/eggFilenameNode.h b/panda/src/egg/eggFilenameNode.h index fd7059d84a..91ae4d35ca 100644 --- a/panda/src/egg/eggFilenameNode.h +++ b/panda/src/egg/eggFilenameNode.h @@ -46,6 +46,14 @@ PUBLISHED: INLINE const Filename &get_fullpath() const; INLINE void set_fullpath(const Filename &fullpath); +public: + class IndirectOrderByBasename { + public: + bool operator () (const EggFilenameNode *a, const EggFilenameNode *b) const { + return a->get_filename().get_basename() < b->get_filename().get_basename(); + } + }; + private: Filename _filename; Filename _fullpath; diff --git a/panda/src/egg/eggTextureCollection.cxx b/panda/src/egg/eggTextureCollection.cxx index a00645c782..381916fd2c 100644 --- a/panda/src/egg/eggTextureCollection.cxx +++ b/panda/src/egg/eggTextureCollection.cxx @@ -421,6 +421,20 @@ sort_by_tref() { NamableOrderByName()); } +//////////////////////////////////////////////////////////////////// +// Function: EggTextureCollection::sort_by_basename +// Access: Public +// Description: Sorts all the textures into alphabetical order by +// the basename part (including extension) of the +// filename. Subsequent operations using begin()/end() +// will traverse in this sorted order. +//////////////////////////////////////////////////////////////////// +void EggTextureCollection:: +sort_by_basename() { + sort(_ordered_textures.begin(), _ordered_textures.end(), + EggFilenameNode::IndirectOrderByBasename()); +} + //////////////////////////////////////////////////////////////////// // Function: EggTextureCollection::add_texture // Access: Public diff --git a/panda/src/egg/eggTextureCollection.h b/panda/src/egg/eggTextureCollection.h index 214e174143..77d01721ac 100644 --- a/panda/src/egg/eggTextureCollection.h +++ b/panda/src/egg/eggTextureCollection.h @@ -83,6 +83,7 @@ PUBLISHED: void uniquify_trefs(); void sort_by_tref(); + void sort_by_basename(); public: // Can be used to traverse all the textures in the collection, in