23 universalCodecs.clear();
24 extensionCodecs.clear();
26 for (CodecPriority::const_iterator it = codecPriority.begin(); it != codecPriority.end(); ++it)
28 codecPriority.clear();
33 if (codecPriority.find(codec) == codecPriority.end()) {
34 codecPriority[codec] = priority;
35 nameCodec[codec->getName()] = codec;
37 std::cout <<
"Registering codec " << codec->getName().c_str();
41 for (Codec::Extensions::const_iterator it = ext->begin(); it != ext->end(); ++it) {
42 std::cout <<
" " << it->c_str();
43 extensionCodecs[*it].insert(codec);
46 std::cout <<
" as universal";
47 universalCodecs.insert(codec);
50 std::cout <<
"." << std::endl;
52 std::cout <<
"Codec " << codec->getName().c_str() <<
" already registered" << std::endl;
58 if (codecPriority.find(codec) != codecPriority.end()) {
59 codecPriority.erase(codec);
60 nameCodec.erase(codec->getName());
63 for (Codec::Extensions::const_iterator it = ext->begin(); it != ext->end(); ++it)
64 extensionCodecs[*it].erase(codec);
66 universalCodecs.erase(codec);
73 NameCodec::const_iterator it = nameCodec.find(name);
74 if (it != nameCodec.end())
75 return it->second;
else
77 std::string(
"No codec with name \"") + name +
"\" has been registered");
80 template<
typename INDEX,
typename T>
88 typename INDEX::const_iterator ait = _index.find(a);
89 typename INDEX::const_iterator bit = _index.find(b);
90 if (ait == _index.end()) {
91 return (bit != _index.end());
93 if (bit == _index.end()) {
104 std::vector<Codec*> candidates;
108 size_t sep = path.find_last_of(
'.');
109 if (sep != std::string::npos && (sep+1) < path.length()) {
110 ExtensionCodecs::const_iterator eit = extensionCodecs.find(
111 path.substr(sep+1, std::string::npos));
112 if (eit != extensionCodecs.end())
113 for (CodecSet::const_iterator esit=eit->second.begin(); esit != eit->second.end(); ++esit)
114 candidates.push_back(*esit);
117 for (CodecSet::const_iterator uit = universalCodecs.begin(); uit != universalCodecs.end(); ++uit)
118 if ((*uit)->canHandle(path,
false, type))
119 candidates.push_back(*uit);
122 if (candidates.begin() != candidates.end()) {
130 for (std::vector<Codec*>::const_reverse_iterator it = candidates.rbegin();
131 it !=
reinterpret_cast<const std::vector<Codec*> &
>(candidates).rend(); ++it)
132 if ((*it)->canHandle(path,
true, type))
138 std::string(
"No registered codec can handle the file \"") + path +
"\"");
144 Codec *codec = findByFile(path, type);
145 return codec->
open(path, type);