[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:36:07 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=7174da0

The following commit has been merged in the master branch:
commit 7174da01927b195855d1bfe557161deeb2f12788
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Mon Mar 8 02:20:03 2004 +0000

    Auto-registration of MakerNote subclasses in the factory, combined mnfactory and makernote into one component again
---
 src/Makefile      |   6 +-
 src/canonmn.cpp   |   8 ++-
 src/canonmn.hpp   |  26 ++++++-
 src/exif.cpp      |   5 +-
 src/exif.hpp      |   7 +-
 src/makernote.cpp | 167 ++++++++++++++++++++++++++++++++++++++++++-
 src/makernote.hpp | 123 ++++++++++++++++++++++++++++++--
 src/mnfactory.cpp | 207 ------------------------------------------------------
 src/mnfactory.hpp | 163 ------------------------------------------
 9 files changed, 320 insertions(+), 392 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 28d74c4..55abaac 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,7 @@
 # 02111-1307, USA.
 #
 # File:      Makefile
-# Version:   $Name:  $ $Revision: 1.12 $
+# Version:   $Name:  $ $Revision: 1.13 $
 # Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
 # History:   10-Dec-03, ahu: created
 #
@@ -51,8 +51,8 @@ include $(top_srcdir)/config.mk
 CCHDR = rcsid.hpp error.hpp
 
 # Add library C++ source files to this list
-CCSRC = canonmn.cpp exif.cpp ifd.cpp image.cpp makernote.cpp mnfactory.cpp     \
-        tags.cpp types.cpp value.cpp
+CCSRC = canonmn.cpp exif.cpp ifd.cpp image.cpp makernote.cpp tags.cpp \
+        types.cpp value.cpp
 
 # Add source files of simple applications to this list
 BINSRC = example1.cpp taglist.cpp exifprint.cpp exiftest.cpp makernote-test.cpp
diff --git a/src/canonmn.cpp b/src/canonmn.cpp
index 1c6ea42..9d91f26 100644
--- a/src/canonmn.cpp
+++ b/src/canonmn.cpp
@@ -20,7 +20,7 @@
  */
 /*
   File:      canonmn.cpp
-  Version:   $Name:  $ $Revision: 1.1 $
+  Version:   $Name:  $ $Revision: 1.2 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   18-Feb-04, ahu: created
              07-Mar-04, ahu: isolated as a separate component
@@ -30,11 +30,13 @@
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.1 $ $RCSfile: canonmn.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.2 $ $RCSfile: canonmn.cpp,v $")
 
 // *****************************************************************************
 // included header files
+#include "types.hpp"
 #include "canonmn.hpp"
+#include "makernote.hpp"
 #include "value.hpp"
 
 // + standard includes
@@ -49,6 +51,8 @@ EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.1 $ $RCSfile: canonmn.cpp,v $")
 // class member definitions
 namespace Exif {
 
+    const CanonMakerNote::RegisterMakerNote CanonMakerNote::register_;
+
     // Canon MakerNote Tag Info
     static const MakerNote::MnTagInfo canonMnTagInfo[] = {
         MakerNote::MnTagInfo(0x0001, "CameraSettings1", "Various camera settings (1)"),
diff --git a/src/canonmn.hpp b/src/canonmn.hpp
index c4382e3..21fa5e5 100644
--- a/src/canonmn.hpp
+++ b/src/canonmn.hpp
@@ -23,7 +23,7 @@
   @brief   Canon MakerNote implemented according to the specification
            "EXIF MakerNote of Canon" <http://www.burren.cx/david/canon.html>
            by David Burren
-  @version $Name:  $ $Revision: 1.1 $
+  @version $Name:  $ $Revision: 1.2 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    18-Feb-04, ahu: created
@@ -86,6 +86,30 @@ namespace Exif {
         //@}
 
     private:
+        //! Structure used to auto-register the MakerNote.
+        struct RegisterMakerNote {
+            //! Default constructor
+            RegisterMakerNote() 
+            {
+                MakerNoteFactory& mnf = MakerNoteFactory::instance();
+                mnf.registerMakerNote("Canon", "*", new CanonMakerNote); 
+            }
+        };
+        /*!
+          The static member variable is (see note) initialized before main and
+          will in the process register the MakerNote class. (Remember the
+          definition of the variable in the implementation file!)
+
+          @note The standard says that, if no function is explicitly called ever
+                in a module, then that module's static data might be never
+                initialized. This clause was introduced to allow dynamic link
+                libraries. The idea is, with this clause the loader is not
+                forced to eagerly load all modules, but load them only on
+                demand.
+         */
+        static const RegisterMakerNote register_; 
+
+        //! The section name (second part of the key) used for makernote tags
         std::string sectionName_;
 
     }; // class CanonMakerNote
diff --git a/src/exif.cpp b/src/exif.cpp
index 6d60113..fb2cc56 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -20,14 +20,14 @@
  */
 /*
   File:      exif.cpp
-  Version:   $Name:  $ $Revision: 1.24 $
+  Version:   $Name:  $ $Revision: 1.25 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   26-Jan-04, ahu: created
              11-Feb-04, ahu: isolated as a component
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.24 $ $RCSfile: exif.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.25 $ $RCSfile: exif.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -39,7 +39,6 @@ EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.24 $ $RCSfile: exif.cpp,v $")
 #include "tags.hpp"
 #include "image.hpp"
 #include "makernote.hpp"
-#include "mnfactory.hpp"
 
 // + standard includes
 #include <iostream>
diff --git a/src/exif.hpp b/src/exif.hpp
index e7f1af4..824ed85 100644
--- a/src/exif.hpp
+++ b/src/exif.hpp
@@ -21,7 +21,7 @@
 /*!
   @file    exif.hpp
   @brief   Encoding and decoding of %Exif data
-  @version $Name:  $ $Revision: 1.25 $
+  @version $Name:  $ $Revision: 1.26 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    09-Jan-04, ahu: created
@@ -37,7 +37,6 @@
 #include "value.hpp"
 #include "ifd.hpp"
 #include "tags.hpp"
-#include "makernote.hpp"
 
 // + standard includes
 #include <string>
@@ -52,6 +51,7 @@ namespace Exif {
 // *****************************************************************************
 // class declarations
     class ExifData;
+    class MakerNote;
 
 // *****************************************************************************
 // class definitions
@@ -641,7 +641,8 @@ namespace Exif {
         TiffHeader tiffHeader_;
         Metadata metadata_;
         Thumbnail thumbnail_;
-        MakerNote* makerNote_;
+        MakerNote* makerNote_;   // Todo: implement reference counting instead
+                                 //       of making ExifData own this pointer
 
         Ifd ifd0_;
         Ifd exifIfd_;
diff --git a/src/makernote.cpp b/src/makernote.cpp
index 4b0c367..d1bc93c 100644
--- a/src/makernote.cpp
+++ b/src/makernote.cpp
@@ -20,13 +20,13 @@
  */
 /*
   File:      makernote.cpp
-  Version:   $Name:  $ $Revision: 1.5 $
+  Version:   $Name:  $ $Revision: 1.6 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   18-Feb-04, ahu: created
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.5 $ $RCSfile: makernote.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.6 $ $RCSfile: makernote.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -130,7 +130,7 @@ namespace Exif {
         if (rc == 0) ifd_.print(std::cerr);
 #endif
         return rc;
-    }
+    } // IfdMakerNote::read
 
     long IfdMakerNote::copy(char* buf, ByteOrder byteOrder, long offset)
     {
@@ -142,4 +142,165 @@ namespace Exif {
          return ifd_.size() + ifd_.dataSize();
     }
 
+    MakerNoteFactory* MakerNoteFactory::instance_ = 0;
+
+    MakerNoteFactory& MakerNoteFactory::instance()
+    {
+        if (0 == instance_) {
+            instance_ = new MakerNoteFactory;
+        }
+        return *instance_;
+    } // MakerNoteFactory::instance
+
+    void MakerNoteFactory::registerMakerNote(const std::string& make, 
+                                             const std::string& model, 
+                                             MakerNote* makerNote)
+    {
+#ifdef DEBUG_MAKERNOTE
+        std::cerr << "Registering MakerNote prototype for \"" 
+                  << make << "\" and \"" << model << "\".
";
+#endif
+
+        // Todo: use case insensitive make and model comparisons
+
+        // find or create a registry entry for make
+        ModelRegistry* modelRegistry = 0;
+        Registry::const_iterator end1 = registry_.end();
+        Registry::const_iterator pos1;
+        for (pos1 = registry_.begin(); pos1 != end1; ++pos1) {
+            if (pos1->first == make) break;
+        }
+        if (pos1 != end1) {
+            modelRegistry = pos1->second;
+        }
+        else {
+            modelRegistry = new ModelRegistry;
+            registry_.push_back(std::make_pair(make, modelRegistry));
+        }
+        // find or create a registry entry for model
+        ModelRegistry::iterator end2 = modelRegistry->end();
+        ModelRegistry::iterator pos2;
+        for (pos2 = modelRegistry->begin(); pos2 != end2; ++pos2) {
+            if (pos2->first == model) break;
+        }
+        if (pos2 != end2) {
+            delete pos2->second;
+            pos2->second = makerNote;
+        }
+        else {
+            modelRegistry->push_back(std::make_pair(model, makerNote));
+        }
+    } // MakerNoteFactory::registerMakerNote
+
+    MakerNote* MakerNoteFactory::create(const std::string& make, 
+                                        const std::string& model) const
+    {
+        // loop through each make of the registry to find the best matching make
+        int matchCount = -1;
+        ModelRegistry* modelRegistry = 0;
+        Registry::const_iterator end1 = registry_.end();
+        Registry::const_iterator pos1;
+        for (pos1 = registry_.begin(); pos1 != end1; ++pos1) {
+            std::pair<bool, int> rc = match(pos1->first, make);
+            if (rc.first && rc.second > matchCount) {
+                matchCount = rc.second;
+                modelRegistry = pos1->second;
+            }
+        }
+        if (modelRegistry == 0) return 0;
+
+        // loop through each model of the model registry to find the best match
+        matchCount = -1;
+        MakerNote* makerNote = 0;
+        ModelRegistry::const_iterator end2 = modelRegistry->end();
+        ModelRegistry::const_iterator pos2;
+        for (pos2 = modelRegistry->begin(); pos2 != end2; ++pos2) {
+            std::pair<bool, int> rc = match(pos2->first, model);
+            if (rc.first && rc.second > matchCount) {
+                matchCount = rc.second;
+                makerNote = pos2->second;
+            }
+        }
+        if (makerNote == 0) return 0;
+
+        return makerNote->clone();
+    } // MakerNoteFactory::create
+
+    std::pair<bool, int> MakerNoteFactory::match(const std::string& regEntry,
+                                                 const std::string& key)
+    {
+        // Todo: make the comparisons case insensitive
+
+        std::string uKey = key;
+        std::string uReg = regEntry;
+
+        int count = 0;                          // number of matching characters
+        std::string::size_type ei = 0;          // index in the registry entry
+        std::string::size_type ki = 0;          // index in the key
+
+        while (ei != std::string::npos) {
+
+            std::string::size_type pos = uReg.find('*', ei);
+            if (pos != ei) {
+                std::string ss = pos == std::string::npos ?
+                    uReg.substr(ei) : uReg.substr(ei, pos - ei);
+
+                if (ki == std::string::npos) {
+                    return std::make_pair(false, 0);
+                }
+
+                bool found = false;
+                // Find the substr ss in the key starting from index ki. 
+                // Take care of the special cases
+                //   + where the substr must match the key from beg to end,
+                //   + from beg,
+                //   + to end 
+                //   + and where it can be anywhere in the key.
+                // If found, ki is adjusted to the position in the key after ss.
+                if (ei == 0 && pos == std::string::npos) { // ei == 0 => ki == 0
+                    if (0 == uKey.compare(ss)) {
+                        found = true;
+                        ki = std::string::npos;
+                    }
+                }
+                else if (ei == 0) { // ei == 0 => ki == 0
+                    if (0 == uKey.compare(0, ss.size(), ss)) {
+                        found = true;
+                        ki = ss.size();
+                    }
+                }
+                else if (pos == std::string::npos) {
+                    if (   ss.size() <= uKey.size() 
+                        && ki <= uKey.size() - ss.size()) {
+                        if (0 == uKey.compare(
+                                uKey.size() - ss.size(), ss.size(), ss)) {
+                            found = true;
+                            ki = std::string::npos;
+                        }
+                    }
+                }
+                else {
+                    std::string::size_type idx = uKey.find(ss, ki); 
+                    if (idx != std::string::npos) {
+                        found = true;
+                        ki = idx + ss.size();
+                    }
+                }
+
+                if (found) {
+                    count += ss.size();
+                }
+                else {
+                    return std::make_pair(false, 0);
+                }
+            } // if the substr is not empty
+
+            ei = pos == std::string::npos ? std::string::npos : pos + 1;
+
+        } // while ei doesn't point to the end of the registry entry
+                                     
+        return std::make_pair(true, count);
+        
+    } // MakerNoteFactory::match
+
 }                                       // namespace Exif
diff --git a/src/makernote.hpp b/src/makernote.hpp
index 92d4eba..14a0a82 100644
--- a/src/makernote.hpp
+++ b/src/makernote.hpp
@@ -20,8 +20,9 @@
  */
 /*!
   @file    makernote.hpp
-  @brief   Defines the %Exif %MakerNote interface and an IFD MakerNote
-  @version $Name:  $ $Revision: 1.5 $
+  @brief   Contains the %Exif %MakerNote interface, IFD %MakerNote and a 
+           MakerNote factory
+  @version $Name:  $ $Revision: 1.6 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    18-Feb-04, ahu: created
@@ -37,6 +38,8 @@
 // + standard includes
 #include <string>
 #include <iosfwd>
+#include <utility>
+#include <vector>
 
 // *****************************************************************************
 // namespace extensions
@@ -55,11 +58,6 @@ namespace Exif {
       - copy the makernote to a character buffer
       - add the makernote tags to the %Exif metadata
       - access Makernote specific tag descriptions and print functions
-
-      Todo: Synchronization with ExifData:
-            Add a MakerNote pointer to ExifData (owner) and Metadata
-            Instead of ExifData as the owner, there should be a reference counter
-            Does Entry need a MakerNote poiner too? (not nice cos of the circ deps)
      */
     class MakerNote {
     public:
@@ -197,6 +195,117 @@ namespace Exif {
         Ifd ifd_;                               //!< MakerNote IFD
 
     }; // class IfdMakerNote
+
+    /*!
+      @brief %MakerNote factory.
+
+      Creates an instance of the %MakerNote for one camera model. The factory is
+      implemented as a singleton, which can be accessed only through the static
+      member function instance().
+    */
+    class MakerNoteFactory {
+    public:
+        /*!
+          @brief Access the makerNote factory. Clients access the task factory
+                 exclusively through this method.
+        */
+        static MakerNoteFactory& instance();
+
+        //! @name Manipulators
+        //@{        
+        /*!
+          @brief Register a %MakerNote prototype for a camera make and model.
+
+          Registers a %MakerNote for a given make and model combination with the
+          factory. Both the make and model strings may contain wildcards ('*',
+          e.g., "Canon*").  The method adds a new makerNote pointer to the
+          registry with the make and model strings provided. It takes ownership
+          of the object pointed to by the maker note pointer provided. If the
+          make already exists, then a new branch for the model is added to the
+          registry. If the model also already exists, then the new makerNote
+          pointer replaces the old one and the maker note pointed to by the old
+          pointer is deleted.
+
+          @param make Camera manufacturer. (Typically the string from the %Exif
+                 make tag.)
+          @param model Camera model. (Typically the string from the %Exif
+                 model tag.)
+          @param makerNote Pointer to the prototype. Ownership is transfered to the
+                 %MakerNote factory.
+        */
+        void registerMakerNote(const std::string& make, 
+                               const std::string& model, 
+                               MakerNote* makerNote);
+        //@}
+
+        //! @name Accessors
+        //@{        
+        /*!
+          @brief Create the appropriate %MakerNote based on camera make and
+                 model, return a pointer to the newly created MakerNote
+                 instance. Return 0 if no %MakerNote is defined for the camera
+                 model.
+
+          The method searches the make-model tree for a make and model
+          combination in the registry that matches the search key. The search is
+          case insensitive (Todo: implement case-insensitive comparisons) and
+          wildcards in the registry entries are supported. First the best
+          matching make is searched, then the best matching model for this make
+          is searched. If there is no matching make or no matching model within
+          the models registered for the best matching make, then no maker note
+          is created and the function returns 0. If a match is found, the
+          function returns a pointer to a clone of the registered prototype. The
+          maker note pointed to is owned by the caller of the function, i.e.,
+          the caller is responsible to delete the returned make note when it is
+          no longer needed.
+          The best match is the match with the most matching characters.
+
+          @param make Camera manufacturer. (Typically the string from the %Exif
+                 make tag.)
+          @param model Camera model. (Typically the string from the %Exif
+                 model tag.)
+          @return A pointer that owns a %MakerNote for the camera model.  If
+                 the camera is not supported, the pointer is 0.
+         */
+        MakerNote* create(const std::string& make, 
+                          const std::string& model) const;
+        //@}
+
+        /*!
+          @brief Match a registry entry with a key (used for make and model).
+
+          The matching algorithm is case insensitive and wildcards ('*') in the
+          registry entry are supported. The best match is the match with the
+          most matching characters.
+
+          @return A pair of which the first component indicates whether or not
+                  the key matches and the second component contains the number
+                  of matching characters.
+         */
+        static std::pair<bool, int> match(const std::string& regEntry, 
+                                          const std::string& key);
+
+    private:
+        //! @name Creators
+        //@{                
+        //! Prevent construction other than through instance().
+        MakerNoteFactory() {}
+        //! Prevent copy construction: not implemented.
+        MakerNoteFactory(const MakerNoteFactory& rhs);
+        //@}
+
+        //! Type used to store model labels and %MakerNote prototype classes
+        typedef std::vector<std::pair<std::string, MakerNote*> > ModelRegistry;
+        //! Type used to store a list of make labels and model registries
+        typedef std::vector<std::pair<std::string, ModelRegistry*> > Registry;
+
+        // DATA
+        //! Pointer to the one and only instance of this class.
+        static MakerNoteFactory* instance_;
+        //! List of makernote types and corresponding prototypes.
+        Registry registry_;
+
+    }; // class MakerNoteFactory
    
 }                                       // namespace Exif
 
diff --git a/src/mnfactory.cpp b/src/mnfactory.cpp
deleted file mode 100644
index f5e50a1..0000000
--- a/src/mnfactory.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-// ***************************************************************** -*- C++ -*-
-/*
- * Copyright (C) 2004 Andreas Huggel <ahuggel at gmx.net>
- * 
- * This program is part of the Exiv2 distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-/*
-  File:      mnfactory.cpp
-  Version:   $Name:  $ $Revision: 1.1 $
-  Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
-  History:   18-Feb-04, ahu: created
-             07-Mar-04, ahu: isolated as a separate component
- */
-// *****************************************************************************
-#include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.1 $ $RCSfile: mnfactory.cpp,v $")
-
-// *****************************************************************************
-// included header files
-#include "mnfactory.hpp"
-#include "makernote.hpp"
-#include "canonmn.hpp"
-
-// + standard includes
-#include <string>
-
-// *****************************************************************************
-// class member definitions
-namespace Exif {
-
-    MakerNoteFactory* MakerNoteFactory::instance_ = 0;
-
-    MakerNoteFactory::MakerNoteFactory()
-    {
-        // Register a prototype of each known MakerNote
-        registerMakerNote("Canon", "*", new CanonMakerNote);
-    } // MakerNoteFactory c'tor
-
-    MakerNoteFactory& MakerNoteFactory::instance()
-    {
-        if (0 == instance_) {
-            instance_ = new MakerNoteFactory;
-        }
-        return *instance_;
-    } // MakerNoteFactory::instance
-
-    void MakerNoteFactory::registerMakerNote(const std::string& make, 
-                                             const std::string& model, 
-                                             MakerNote* makerNote)
-    {
-        // Todo: use case insensitive make and model comparisons
-
-        // find or create a registry entry for make
-        ModelRegistry* modelRegistry = 0;
-        Registry::const_iterator end1 = registry_.end();
-        Registry::const_iterator pos1;
-        for (pos1 = registry_.begin(); pos1 != end1; ++pos1) {
-            if (pos1->first == make) break;
-        }
-        if (pos1 != end1) {
-            modelRegistry = pos1->second;
-        }
-        else {
-            modelRegistry = new ModelRegistry;
-            registry_.push_back(std::make_pair(make, modelRegistry));
-        }
-        // find or create a registry entry for model
-        ModelRegistry::iterator end2 = modelRegistry->end();
-        ModelRegistry::iterator pos2;
-        for (pos2 = modelRegistry->begin(); pos2 != end2; ++pos2) {
-            if (pos2->first == model) break;
-        }
-        if (pos2 != end2) {
-            delete pos2->second;
-            pos2->second = makerNote;
-        }
-        else {
-            modelRegistry->push_back(std::make_pair(model, makerNote));
-        }
-    } // MakerNoteFactory::registerMakerNote
-
-    MakerNote* MakerNoteFactory::create(const std::string& make, 
-                                        const std::string& model) const
-    {
-        // loop through each make of the registry to find the best matching make
-        int matchCount = -1;
-        ModelRegistry* modelRegistry = 0;
-        Registry::const_iterator end1 = registry_.end();
-        Registry::const_iterator pos1;
-        for (pos1 = registry_.begin(); pos1 != end1; ++pos1) {
-            std::pair<bool, int> rc = match(pos1->first, make);
-            if (rc.first && rc.second > matchCount) {
-                matchCount = rc.second;
-                modelRegistry = pos1->second;
-            }
-        }
-        if (modelRegistry == 0) return 0;
-
-        // loop through each model of the model registry to find the best match
-        matchCount = -1;
-        MakerNote* makerNote = 0;
-        ModelRegistry::const_iterator end2 = modelRegistry->end();
-        ModelRegistry::const_iterator pos2;
-        for (pos2 = modelRegistry->begin(); pos2 != end2; ++pos2) {
-            std::pair<bool, int> rc = match(pos2->first, model);
-            if (rc.first && rc.second > matchCount) {
-                matchCount = rc.second;
-                makerNote = pos2->second;
-            }
-        }
-        if (makerNote == 0) return 0;
-
-        return makerNote->clone();
-    } // MakerNoteFactory::create
-
-    std::pair<bool, int> MakerNoteFactory::match(const std::string& regEntry,
-                                                 const std::string& key)
-    {
-        // Todo: make the comparisons case insensitive
-
-        std::string uKey = key;
-        std::string uReg = regEntry;
-
-        int count = 0;                          // number of matching characters
-        std::string::size_type ei = 0;          // index in the registry entry
-        std::string::size_type ki = 0;          // index in the key
-
-        while (ei != std::string::npos) {
-
-            std::string::size_type pos = uReg.find('*', ei);
-            if (pos != ei) {
-                std::string ss = pos == std::string::npos ?
-                    uReg.substr(ei) : uReg.substr(ei, pos - ei);
-
-                if (ki == std::string::npos) {
-                    return std::make_pair(false, 0);
-                }
-
-                bool found = false;
-                // Find the substr ss in the key starting from index ki. 
-                // Take care of the special cases
-                //   + where the substr must match the key from beg to end,
-                //   + from beg,
-                //   + to end 
-                //   + and where it can be anywhere in the key.
-                // If found, ki is adjusted to the position in the key after ss.
-                if (ei == 0 && pos == std::string::npos) { // ei == 0 => ki == 0
-                    if (0 == uKey.compare(ss)) {
-                        found = true;
-                        ki = std::string::npos;
-                    }
-                }
-                else if (ei == 0) { // ei == 0 => ki == 0
-                    if (0 == uKey.compare(0, ss.size(), ss)) {
-                        found = true;
-                        ki = ss.size();
-                    }
-                }
-                else if (pos == std::string::npos) {
-                    if (   ss.size() <= uKey.size() 
-                        && ki <= uKey.size() - ss.size()) {
-                        if (0 == uKey.compare(
-                                uKey.size() - ss.size(), ss.size(), ss)) {
-                            found = true;
-                            ki = std::string::npos;
-                        }
-                    }
-                }
-                else {
-                    std::string::size_type idx = uKey.find(ss, ki); 
-                    if (idx != std::string::npos) {
-                        found = true;
-                        ki = idx + ss.size();
-                    }
-                }
-
-                if (found) {
-                    count += ss.size();
-                }
-                else {
-                    return std::make_pair(false, 0);
-                }
-            } // if the substr is not empty
-
-            ei = pos == std::string::npos ? std::string::npos : pos + 1;
-
-        } // while ei doesn't point to the end of the registry entry
-                                     
-        return std::make_pair(true, count);
-        
-    } // MakerNoteFactory::match
-
-}                                       // namespace Exif
diff --git a/src/mnfactory.hpp b/src/mnfactory.hpp
deleted file mode 100644
index 8097a08..0000000
--- a/src/mnfactory.hpp
+++ /dev/null
@@ -1,163 +0,0 @@
-// ***************************************************************** -*- C++ -*-
-/*
- * Copyright (C) 2004 Andreas Huggel <ahuggel at gmx.net>
- * 
- * This program is part of the Exiv2 distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-/*!
-  @file    mnfactory.hpp
-  @brief   Factory for MakerNote classes
-  @version $Name:  $ $Revision: 1.1 $
-  @author  Andreas Huggel (ahu)
-           <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
-  @date    18-Feb-04, ahu: created
-           07-Mar-04, ahu: isolated as a separate component
- */
-#ifndef MNFACTORY_HPP_
-#define MNFACTORY_HPP_
-
-// *****************************************************************************
-// included header files
-
-// + standard includes
-#include <string>
-#include <utility>
-#include <vector>
-
-// *****************************************************************************
-// namespace extensions
-namespace Exif {
-
-    class MakerNote;
-
-// *****************************************************************************
-// class definitions
-
-    /*!
-      @brief %MakerNote factory.
-
-      Creates an instance of the %MakerNote for one camera model. The factory is
-      implemented as a singleton, which can be accessed only through the static
-      member function instance().
-    */
-    class MakerNoteFactory {
-    public:
-        /*!
-          @brief Access the makerNote factory. Clients access the task factory
-                 exclusively through this method.
-        */
-        static MakerNoteFactory& instance();
-
-        //! @name Manipulators
-        //@{        
-        /*!
-          @brief Register a %MakerNote prototype for a camera make and model.
-
-          Registers a %MakerNote for a given make and model combination with the
-          factory. Both the make and model strings may contain wildcards ('*',
-          e.g., "Canon*").  The method adds a new makerNote pointer to the
-          registry with the make and model strings provided. It takes ownership
-          of the object pointed to by the maker note pointer provided. If the
-          make already exists, then a new branch for the model is added to the
-          registry. If the model also already exists, then the new makerNote
-          pointer replaces the old one and the maker note pointed to by the old
-          pointer is deleted.
-
-          @param make Camera manufacturer. (Typically the string from the %Exif
-                 make tag.)
-          @param model Camera model. (Typically the string from the %Exif
-                 model tag.)
-          @param makerNote Pointer to the prototype. Ownership is transfered to the
-                 %MakerNote factory.
-        */
-        void registerMakerNote(const std::string& make, 
-                               const std::string& model, 
-                               MakerNote* makerNote);
-        //@}
-
-        //! @name Accessors
-        //@{        
-        /*!
-          @brief Create the appropriate %MakerNote based on camera make and
-                 model, return a pointer to the newly created MakerNote
-                 instance. Return 0 if no %MakerNote is defined for the camera
-                 model.
-
-          The method searches the make-model tree for a make and model
-          combination in the registry that matches the search key. The search is
-          case insensitive (Todo: implement case-insensitive comparisons) and
-          wildcards in the registry entries are supported. First the best
-          matching make is searched, then the best matching model for this make
-          is searched. If there is no matching make or no matching model within
-          the models registered for the best matching make, then no maker note
-          is created and the function returns 0. If a match is found, the
-          function returns a pointer to a clone of the registered prototype. The
-          maker note pointed to is owned by the caller of the function, i.e.,
-          the caller is responsible to delete the returned make note when it is
-          no longer needed.
-          The best match is the match with the most matching characters.
-
-          @param make Camera manufacturer. (Typically the string from the %Exif
-                 make tag.)
-          @param model Camera model. (Typically the string from the %Exif
-                 model tag.)
-          @return A pointer that owns a %MakerNote for the camera model.  If
-                 the camera is not supported, the pointer is 0.
-         */
-        MakerNote* create(const std::string& make, 
-                          const std::string& model) const;
-        //@}
-
-        /*!
-          @brief Match a registry entry with a key (used for make and model).
-
-          The matching algorithm is case insensitive and wildcards ('*') in the
-          registry entry are supported. The best match is the match with the
-          most matching characters.
-
-          @return A pair of which the first component indicates whether or not
-                  the key matches and the second component contains the number
-                  of matching characters.
-         */
-        static std::pair<bool, int> match(const std::string& regEntry, 
-                                          const std::string& key);
-
-    private:
-        //! @name Creators
-        //@{                
-        //! Prevent construction other than through instance().
-        MakerNoteFactory();
-        //! Prevent copy construction: not implemented.
-        MakerNoteFactory(const MakerNoteFactory& rhs);
-        //@}
-
-        //! Type used to store model labels and %MakerNote prototype classes
-        typedef std::vector<std::pair<std::string, MakerNote*> > ModelRegistry;
-        //! Type used to store a list of make labels and model registries
-        typedef std::vector<std::pair<std::string, ModelRegistry*> > Registry;
-
-        // DATA
-        //! Pointer to the one and only instance of this class.
-        static MakerNoteFactory* instance_;
-        //! List of makernote types and corresponding prototypes.
-        Registry registry_;
-
-    }; // class MakerNoteFactory
-   
-}                                       // namespace Exif
-
-#endif                                  // #ifndef MNFACTORY_HPP_

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list