Dictionary basics.
Dictionary basics.
#include <iostream>
int main()
{
#if 0
{
}
#endif
#if 1
{
dict.
set(
"test1",
"test value");
dict.
set(
"test2", 31337);
cout << dict.
get(
"test1") << endl
<< dict.
get(
"test2") << endl;
{
shared_ptr<char> sptr;
{
cout << ptr.get() << endl;
sptr = std::move(ptr);
}
cout << sptr.get() << endl;
}
cout << dict[1] << endl;
}
{
dict.
set(
"test1",
"test value");
dict.
set(
"test2", 31337);
cout << endl;
cout <<
"ptr: " << (
void*)dict.
raw() << endl;
cout << dict.
get(
"test1") << endl
<< dict.
get(
"test2") << endl;
cout << endl;
cout <<
"ptr: " << (
void*)dict.
raw() << endl;
cout << dict.
get(
"test1") << endl
<< dict.
get(
"test2") << endl;
cout <<
"ptr: " << (
void*)dict2.
raw() << endl;
cout << dict2.
get(
"test1") << endl
<< dict2.
get(
"test2") << endl;
dict3 = dict;
cout << endl;
cout <<
"ptr: " << (
void*)dict.
raw() << endl;
cout << dict.
get(
"test1") << endl
<< dict.
get(
"test2") << endl;
cout <<
"ptr: " << (
void*)dict3.
raw() << endl;
cout << dict3.
get(
"test1") << endl
<< dict3.
get(
"test2") << endl;
cout << endl;
cout <<
"ptr: " << (
void*)dict2.
raw() << endl;
cout <<
"ptr: " << (
void*)dict4.
raw() << endl;
cout << dict4.
get(
"test1") << endl
<< dict4.
get(
"test2") << endl;
dict5 = std::move(dict3);
cout << endl;
cout <<
"ptr: " << (
void*)dict3.
raw() << endl;
cout <<
"ptr: " << (
void*)dict5.
raw() << endl;
cout << dict5.
get(
"test1") << endl
<< dict5.
get(
"test2") << endl;
}
{
dict.
set(
"test1",
"test value");
dict.
set(
"test2", 31337);
dict.
set(
"test3",
"other value");
for (auto const &i : dict)
{
cout << i.key() << " -> " << i.value() << endl;
}
for (
int i = 0; it != dict.
end(); ++it, ++i)
{
cout << (*it).key() << " -> " << (*it).value() << endl;
cout << it->key() << " -> " << it->value() << endl;
it->set(to_string(i));
}
{
for (
int i = 0; it != dict.
cend(); ++it, ++i)
{
cout << (*it).key() << " -> " << (*it).value() << endl;
cout << it->key() << " -> " << it->value() << endl;
}
}
cout << "End\n";
}
{
{"init1", "value1"},
{"init2", "value2"}
};
for (auto const &i : dict)
{
cout << i.key() << " -> " << i.value() << endl;
}
dict = {
{"init3", "value3"},
{"init4", "value4"},
};
for (auto const &i : dict)
{
cout << i.key() << " -> " << i.value() << endl;
}
}
{
{
{"i1", "v1"},
{"i2", "v2"}
},
{
{"i3", "v3"},
{"i4", "v4"}
}
};
auto v = arr[0];
v.set("i1", "change1");
auto c = arr[0];
c.set("i1", "change2");
auto d = arr[0];
cout << v.get("i1") << ", " << c.get("i1") << ", " << d.get("i1") << endl;
auto& e = arr[0];
e.set("i1", "change3");
auto& f = arr[0];
cout << e.get("i1") << ", " << f.get("i1") << endl;
}
{
dict.
parseString(
"key3=val1;key4=val2",
string(
"="),
string(
";"));
error_code ec;
cout <<
" str: " << dict.
toString(
':',
',', ec) << endl;
cout << " err: " << ec << ", " << ec.message() << endl;
cout <<
" str: " << dict.
toString(
':',
'\0', ec) << endl;
cout << " err: " << ec << ", " << ec.message() << endl;
cout << " str: " << raw.get() << endl;
cout << " err: " << ec << ", " << ec.message() << endl;
}
#endif
#if 1
{
#if 0
{
AVDictionary *rdict = nullptr;
av_dict_set(&rdict, "rdict", "rvalue", 0);
{"dict", "val"}
};
}
#endif
#if 0
{
dict["test"] = "value";
dict["test2"] = "fdsfdsfdsfdsfsdfsd";
av_freep(ptr2);
cout << (
void*)dict.
raw() << endl;
AVDictionary *rdict = nullptr;
av_dict_set(&rdict, "rdict", "rvalue", 0);
*ptr2 = rdict;
}
#endif
}
#endif
#if 0
{
{
{"key1", "val1"}
},
{
{"key2", "val2"}
},
};
auto arr2 = arr;
for (size_t i = 0; i < arr2.size(); ++i)
{
auto ptr1 = raw[i];
auto ptr2 = arr2[i].raw();
auto ptr3 = arr[i].raw();
cout << (void*)ptr1 << " vs " << (void*)ptr2 << " vs " << (void*)ptr3 << endl;
}
}
#endif
return 0;
}
Array of Dictinaries wrapper.
Definition dictionary.h:808
const AVDictionary *const * raws() const
The raw array, read-only.
Implements interface to access to the AVDictionary entity.
Definition dictionary.h:38
AvStringPtr toRawStringPtr(const char keyValSep, const char pairsSep, OptionalErrorCode ec=throws()) const
toRawStringPtr - converts dictionary to the raw string (char*) and protect it with smart pointer (std...
AVDictionary ** rawPtr() noexcept
Address of the internal pointer, for FFmpeg calls that take AVDictionary**.
void assign(AVDictionary *dict, bool takeOwning=true) noexcept
assign - assign new resouces Old dictionary destroyes (if owning).
Iterator begin()
First entry.
std::string toString(const char keyValSep, const char pairsSep, OptionalErrorCode ec=throws()) const
toString - converts dictionary to the string representation (serialize)
auto set(const Key &key, const Value &value, OptionalErrorCode ec=throws(), int flags=0) -> typename std::enable_if<(std::is_same< Key, std::string >::value||std::is_same< typename std::remove_cv< typename std::decay< Key >::type >::type, char * >::value) &&(std::is_same< Value, std::string >::value||std::is_same< typename std::remove_cv< typename std::decay< Value >::type >::type, char * >::value||std::is_integral< Value >::value), void >::type
set - set new value for key or add new dictionary item (or create dictionary) If dictionary empty (nu...
Definition dictionary.h:653
void parseString(const Str &str, const Sep1 &keyValSep, const Sep2 &pairsSep, int flags=0, OptionalErrorCode ec=throws())
parseString - process string with options and fill dictionary String examples:
Definition dictionary.h:686
const char * get(const char *key, int flags=0) const noexcept
Value for a key.
ConstIterator cbegin() const
First entry, read-only, for explicit const traversal.
Iterator end()
End of the iteration.
ConstIterator cend() const
End of the read-only traversal.
AVDictionary * release()
release - drops ownershipping
AVDictionary wrappers: Dictionary and DictionaryArray.
Root namespace of the library.
Definition audioresampler.h:19
const T * raw() const
Read access to the wrapped object.
Definition ffmpeg.h:56
RAII holder for strings allocated by FFmpeg internals.
Definition dictionary.h:89