contrib/oul/ouml/image_database.h
Go to the documentation of this file.
00001 // This is oul/ouml/image_database.h
00002 #ifndef OTAGO__image_database_INCLUDED_
00003 #define OTAGO__image_database_INCLUDED_
00004 //:
00005 // \file
00006 //
00007 // An image database. Basically maintains a list of labels and
00008 // associated images. And allows for saving and loading a database.
00009 // Ideally, this would form an inheritance hierarchy or be a templated
00010 // class, but I'm looking for simplicity at the moment.
00011 //
00012 // The images inserted into the database WILL be deleted on
00013 // destruction of the database. So only insert things you don't want
00014 // to persist.
00015 //
00016 // \author Brendan McCane
00017 // \date 17 July 2001
00018 //
00019 // Copyright (c) 2001 Brendan McCane
00020 // University of Otago, Dunedin, New Zealand
00021 // Reproduction rights limited as described in the COPYRIGHT file.
00022 //
00023 //----------------------------------------------------------------------
00024 
00025 #include <vcl_sys/types.h>
00026 #include <vcl_cstring.h> // for strcpy(), strcmp()
00027 #include <vcl_map.h>
00028 #include <vcl_utility.h>
00029 #include <vil1/vil1_memory_image.h>
00030 
00031 class ImageDatabase
00032 {
00033   // the comparison object for the map
00034  public:
00035   struct ltstr
00036   {
00037     bool operator()(const char* s1, const char* s2) const;
00038   };
00039 
00040  private:
00041   // the multimap to store label/image pairs
00042   vcl_multimap<const char*, vil1_memory_image *, ltstr> image_db;
00043 
00044  public:
00045   // typedefs for access to the image_db
00046   typedef vcl_multimap<const char*, vil1_memory_image *, ltstr>::iterator iterator;
00047   typedef vcl_multimap<const char*, vil1_memory_image *, ltstr>::const_iterator const_iterator;
00048   typedef vcl_pair<const char *, vil1_memory_image *> value_type;
00049 
00050   ImageDatabase(){}
00051   ~ImageDatabase();
00052   inline iterator insert(const char *label, vil1_memory_image *image)
00053     {char *new_label=new char[200]; vcl_strcpy(new_label, label);
00054     value_type ins(new_label, image); return image_db.insert(ins);}
00055   inline iterator begin(){return image_db.begin();}
00056   inline iterator end(){return image_db.end();}
00057   inline const_iterator begin() const {return image_db.begin();}
00058   inline const_iterator end() const {return image_db.end();}
00059   inline vcl_pair<iterator, iterator> equal_range(const char *&label)
00060     {return image_db.equal_range(label);}
00061   inline vcl_pair<const_iterator, const_iterator> equal_range(const char *&label)
00062     const {return image_db.equal_range(label);}
00063   inline bool label_exists(const char *label) const
00064     {return image_db.count(label)>0;}
00065   void clear();
00066 
00067   bool save(const char *name, const char *imagetype);
00068   bool load(const char *name);
00069 };
00070 
00071 #endif // OTAGO__image_database_INCLUDED_