locate_images.h revision cc2ee177dbb3befca43e36cfc56778b006c3d050
1/**
2 * @file locate_images.h
3 * Location of binary images
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author Philippe Elie
9 * @author John Levon
10 */
11
12#ifndef LOCATE_IMAGES_H
13#define LOCATE_IMAGES_H
14
15#include <string>
16#include <map>
17#include <vector>
18
19#include "image_errors.h"
20
21/**
22 * A class containing mappings from an image basename,
23 * such as 'floppy.ko', to locations in the paths passed
24 * in to populate().
25 *
26 * The name may exist multiple times; all locations are recorded
27 * in this container.
28 */
29class extra_images {
30public:
31	/// add all filenames found in the given paths, recursively
32	void populate(std::vector<std::string> const & paths);
33
34	/// base class for matcher functors object
35	struct matcher {
36		std::string const & value;
37	public:
38		explicit matcher(std::string const & v) : value(v) {}
39		virtual ~matcher() {}
40		/// default functor allowing trivial match
41		virtual bool operator()(std::string const & str) const {
42			return str == value;
43		}
44	};
45
46	/**
47	 * return a vector of all directories that match the functor
48	 */
49	std::vector<std::string> const find(matcher const & match) const;
50
51	/// return a vector of all directories that match the given name
52	std::vector<std::string> const find(std::string const & name) const;
53
54private:
55	typedef std::multimap<std::string, std::string> images_t;
56	typedef images_t::value_type value_type;
57	typedef images_t::const_iterator const_iterator;
58
59	/// map from image basename to owning directory
60	images_t images;
61};
62
63/**
64 * @param archive_path archive prefix path
65 * @param extra_images container where all extra candidate filenames are stored
66 * @param image_name binary image name
67 * @param error errors are flagged in this passed enum ref
68 *
69 * Locate a (number of) matching absolute paths to the given image name.
70 * If we fail to find the file we fill in error and return the original string.
71 */
72std::string const
73find_image_path(std::string const & archive_path,
74		std::string const & image_name,
75                extra_images const & extra_images,
76                image_error & error);
77
78#endif /* LOCATE_IMAGES_H */
79