opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /***********************************************************************
joeverbout 0:ea44dc9ed014 2 * Software License Agreement (BSD License)
joeverbout 0:ea44dc9ed014 3 *
joeverbout 0:ea44dc9ed014 4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
joeverbout 0:ea44dc9ed014 5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
joeverbout 0:ea44dc9ed014 6 *
joeverbout 0:ea44dc9ed014 7 * THE BSD LICENSE
joeverbout 0:ea44dc9ed014 8 *
joeverbout 0:ea44dc9ed014 9 * Redistribution and use in source and binary forms, with or without
joeverbout 0:ea44dc9ed014 10 * modification, are permitted provided that the following conditions
joeverbout 0:ea44dc9ed014 11 * are met:
joeverbout 0:ea44dc9ed014 12 *
joeverbout 0:ea44dc9ed014 13 * 1. Redistributions of source code must retain the above copyright
joeverbout 0:ea44dc9ed014 14 * notice, this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 15 * 2. Redistributions in binary form must reproduce the above copyright
joeverbout 0:ea44dc9ed014 16 * notice, this list of conditions and the following disclaimer in the
joeverbout 0:ea44dc9ed014 17 * documentation and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 18 *
joeverbout 0:ea44dc9ed014 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
joeverbout 0:ea44dc9ed014 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
joeverbout 0:ea44dc9ed014 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
joeverbout 0:ea44dc9ed014 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
joeverbout 0:ea44dc9ed014 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
joeverbout 0:ea44dc9ed014 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
joeverbout 0:ea44dc9ed014 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
joeverbout 0:ea44dc9ed014 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
joeverbout 0:ea44dc9ed014 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
joeverbout 0:ea44dc9ed014 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
joeverbout 0:ea44dc9ed014 29 *************************************************************************/
joeverbout 0:ea44dc9ed014 30
joeverbout 0:ea44dc9ed014 31 #ifndef OPENCV_FLANN_OBJECT_FACTORY_H_
joeverbout 0:ea44dc9ed014 32 #define OPENCV_FLANN_OBJECT_FACTORY_H_
joeverbout 0:ea44dc9ed014 33
joeverbout 0:ea44dc9ed014 34 #include <map>
joeverbout 0:ea44dc9ed014 35
joeverbout 0:ea44dc9ed014 36 namespace cvflann
joeverbout 0:ea44dc9ed014 37 {
joeverbout 0:ea44dc9ed014 38
joeverbout 0:ea44dc9ed014 39 class CreatorNotFound
joeverbout 0:ea44dc9ed014 40 {
joeverbout 0:ea44dc9ed014 41 };
joeverbout 0:ea44dc9ed014 42
joeverbout 0:ea44dc9ed014 43 template<typename BaseClass,
joeverbout 0:ea44dc9ed014 44 typename UniqueIdType,
joeverbout 0:ea44dc9ed014 45 typename ObjectCreator = BaseClass* (*)()>
joeverbout 0:ea44dc9ed014 46 class ObjectFactory
joeverbout 0:ea44dc9ed014 47 {
joeverbout 0:ea44dc9ed014 48 typedef ObjectFactory<BaseClass,UniqueIdType,ObjectCreator> ThisClass;
joeverbout 0:ea44dc9ed014 49 typedef std::map<UniqueIdType, ObjectCreator> ObjectRegistry;
joeverbout 0:ea44dc9ed014 50
joeverbout 0:ea44dc9ed014 51 // singleton class, private constructor
joeverbout 0:ea44dc9ed014 52 ObjectFactory() {}
joeverbout 0:ea44dc9ed014 53
joeverbout 0:ea44dc9ed014 54 public:
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 bool subscribe(UniqueIdType id, ObjectCreator creator)
joeverbout 0:ea44dc9ed014 57 {
joeverbout 0:ea44dc9ed014 58 if (object_registry.find(id) != object_registry.end()) return false;
joeverbout 0:ea44dc9ed014 59
joeverbout 0:ea44dc9ed014 60 object_registry[id] = creator;
joeverbout 0:ea44dc9ed014 61 return true;
joeverbout 0:ea44dc9ed014 62 }
joeverbout 0:ea44dc9ed014 63
joeverbout 0:ea44dc9ed014 64 bool unregister(UniqueIdType id)
joeverbout 0:ea44dc9ed014 65 {
joeverbout 0:ea44dc9ed014 66 return object_registry.erase(id) == 1;
joeverbout 0:ea44dc9ed014 67 }
joeverbout 0:ea44dc9ed014 68
joeverbout 0:ea44dc9ed014 69 ObjectCreator create(UniqueIdType id)
joeverbout 0:ea44dc9ed014 70 {
joeverbout 0:ea44dc9ed014 71 typename ObjectRegistry::const_iterator iter = object_registry.find(id);
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 if (iter == object_registry.end()) {
joeverbout 0:ea44dc9ed014 74 throw CreatorNotFound();
joeverbout 0:ea44dc9ed014 75 }
joeverbout 0:ea44dc9ed014 76
joeverbout 0:ea44dc9ed014 77 return iter->second;
joeverbout 0:ea44dc9ed014 78 }
joeverbout 0:ea44dc9ed014 79
joeverbout 0:ea44dc9ed014 80 static ThisClass& instance()
joeverbout 0:ea44dc9ed014 81 {
joeverbout 0:ea44dc9ed014 82 static ThisClass the_factory;
joeverbout 0:ea44dc9ed014 83 return the_factory;
joeverbout 0:ea44dc9ed014 84 }
joeverbout 0:ea44dc9ed014 85 private:
joeverbout 0:ea44dc9ed014 86 ObjectRegistry object_registry;
joeverbout 0:ea44dc9ed014 87 };
joeverbout 0:ea44dc9ed014 88
joeverbout 0:ea44dc9ed014 89 }
joeverbout 0:ea44dc9ed014 90
joeverbout 0:ea44dc9ed014 91 #endif /* OPENCV_FLANN_OBJECT_FACTORY_H_ */
joeverbout 0:ea44dc9ed014 92