Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libdvbtee: update embedded valobj library to v1.1.1 #18

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
910a107
libdvbtee: move value file locations up one level & fix namespace
mkrufky Apr 4, 2015
c98dc96
libdvbtee: clean up qmake .pri files
mkrufky Apr 4, 2015
e81f342
decode/value: now using namespace valueobj
mkrufky Apr 7, 2015
5b380fc
valueobj: fix warning: type qualifiers ignored on function return typ…
mkrufky Apr 8, 2015
a3e5cd3
valueobj: object: convert inline set() functions to normal functions
mkrufky Apr 8, 2015
5a82cdd
valueobj: array: convert inline push() functions to normal functions,…
mkrufky Apr 8, 2015
5016c8f
valueobj: value: remove unused (and incorrect) function, value<T>::se…
mkrufky Apr 9, 2015
e0158b7
valueobj: move Value class template definition to value.cpp
mkrufky Apr 9, 2015
b41ab80
valueobj: move Object class template definition to object.cpp
mkrufky Apr 9, 2015
bfbe9e4
valueobj: move Array class template definition to array.cpp
mkrufky Apr 9, 2015
e760997
valueobj: add .pro file to enable building in src/ as a static library
mkrufky Jul 5, 2015
a045ae3
valueobj: clean up QMAKE_CXXFLAGS in value.pro
mkrufky Jul 5, 2015
93a1e5f
libvalueobj: build now using autotools
mkrufky Jul 9, 2015
a865409
value: avoid return of stack variable address
mkrufky Jul 12, 2015
c3e6642
value/array: dont assign index to index
mkrufky Jul 12, 2015
e1df2f4
value/object: fix explicit specialization after instantiation
mkrufky Jul 14, 2015
e8e3a1b
value: add support for primitive type 'unsigned long long'
mkrufky Jul 14, 2015
dea43d7
value/object: inline template function const ValueBase* set(int key, …
mkrufky Jul 15, 2015
2785d5f
value/array: implement array template for all types
mkrufky Jul 15, 2015
fcf96b2
value: add support for primitive type 'long long'
mkrufky Jul 15, 2015
c8a9b20
value/object: remove internal definition of template const ValueBase*…
mkrufky Jul 15, 2015
4e57aba
value/object: inline template function const ValueBase* set(std::stri…
mkrufky Jul 15, 2015
c8a4865
value/object: inline template function const T& get(std::string key) …
mkrufky Jul 15, 2015
0d8717c
value: Value<T> copy constructor should not be explicit
mkrufky Nov 3, 2015
9705a71
value: ValueUndefined copy constructor should not be explicit
mkrufky Nov 3, 2015
d156907
value/array: add support for push(X) as std::string where X is char* …
mkrufky Nov 8, 2015
d8f0bee
value/array: add support for set(key, X) as std::string where X is ch…
mkrufky Nov 8, 2015
ea18d4e
valobj: s/"VALUEOBJ"/"VALOBJ"/g
mkrufky Nov 8, 2015
0137c09
value/object: copy constructor should set keys explicitly and not rel…
mkrufky Nov 12, 2015
cdef9f0
value/object: remove count in iterator loop
mkrufky Nov 12, 2015
819ebd4
value/array: remove count in iterator loop
mkrufky Nov 12, 2015
45a20ab
value:array|object: dont #include <stdio.h> #if !DBG
mkrufky Nov 12, 2015
8a07486
valobj: move headers to include/valobj/
mkrufky Nov 26, 2015
c21f3bd
appveyor.yml: link tests against static libvalueobj.a
mkrufky Nov 26, 2015
0df0a10
.travis.yml: add [gl]cov & coveralls.io upload on linux
mkrufky Nov 28, 2015
30d4616
valobj: add handle.h (all-header)
mkrufky Nov 9, 2015
ffb08db
value/handle: move function definitions to handle.cpp
mkrufky Nov 9, 2015
cdfa63d
value/handle: add conversion operators
mkrufky Nov 9, 2015
6a34869
value/handle: header should include string and stddef.h
mkrufky Nov 9, 2015
d2f7283
value/handle: setters take an optional name
mkrufky Nov 9, 2015
2249c70
value/handle: template conversion constructor takes an optional name
mkrufky Nov 9, 2015
1d2cb71
value/handle: clean up header
mkrufky Nov 9, 2015
e9f5775
value/handle: only build value or value reference assignment operator…
mkrufky Nov 9, 2015
962a761
value/handle: temporarily fix warning: control reaches end of non-voi…
mkrufky Nov 9, 2015
975ec7d
value/handle: get() returns a ValueBase* rather than a const ValueBase*
mkrufky Nov 11, 2015
1de4c05
value/array: begin converting push() functionality to use handles
mkrufky Nov 11, 2015
825639f
value/array: begin converting set() functionality to use handles
mkrufky Nov 11, 2015
e00e270
value/array: inline push(T) and remove push([const] char*)
mkrufky Nov 11, 2015
d75ab48
value/array: remove 5 push([type], std::string idx) wrapper functions
mkrufky Nov 11, 2015
68961cd
value/array: inline set([int|std::string], T) and remove set([int|std…
mkrufky Nov 11, 2015
cf80754
value/handle: add missing constructors and operators
mkrufky Nov 12, 2015
87ca8dd
value/array: change KeyValueVector to store Handle rather than ValueB…
mkrufky Nov 12, 2015
1991a19
value/array: move set(Handle) below the push() functions
mkrufky Nov 12, 2015
3eb7923
value/array: pass key independantly from Handle in set() functions
mkrufky Nov 12, 2015
cce84db
value/object: add set & setByRef taking Handle
mkrufky Nov 12, 2015
57d8106
value/object: remove 7 set(std::string key, [type]) wrapper functions
mkrufky Nov 12, 2015
40f0032
value/object: remove setByRef template function
mkrufky Nov 12, 2015
81653d9
value/object: change KeyValueMap to store Handle rather than ValueBase*
mkrufky Nov 12, 2015
82012de
value/object: add Handle& getHandle(std::String|int key) const
mkrufky Nov 12, 2015
10d9054
value/object: disable get() returning ValueBase* in favor of returnin…
mkrufky Nov 12, 2015
26dddd1
value/array: disable get() returning ValueBase* in favor of returning…
mkrufky Nov 12, 2015
17f6ff5
value/array: disable getByName() returning ValueBase* in favor of ret…
mkrufky Nov 12, 2015
71cad77
value/object: setByRef(std::string&, Handle&) returns Handle& rather …
mkrufky Nov 12, 2015
f6fde7a
value/object: set(std::string&, Handle&) returns Handle& rather than …
mkrufky Nov 12, 2015
e6ec99f
value/object: rename getHandle() to get()
mkrufky Nov 12, 2015
eb1fcc9
value/object: clean up const std::string Object::toJson() const
mkrufky Nov 12, 2015
adcf2ae
value/array: push() returns Handle& rather than const ValueBase*
mkrufky Nov 13, 2015
c60e117
value/array: set(key, val) returns bool rather than const ValueBase*
mkrufky Nov 16, 2015
aedcef2
value/array: convert indices to std::map<std::string, Handle*>
mkrufky Nov 23, 2015
2a76804
value/array: use vector.at(idx) rather than vector[idx]
mkrufky Nov 29, 2015
dcf8768
value/object: use double quotes rather than single quotes
mkrufky Jan 30, 2016
d0dd1e1
valobj: update copyright year
mkrufky Jan 31, 2016
9358d7b
Merge branch 'master' into handle
mkrufky Jan 31, 2016
3d57286
handle: update copyright year
mkrufky Jan 31, 2016
4ba4028
merge history from valobj v1.1.0
mkrufky Jun 1, 2016
a18ae0b
fix: libdvbtee/value/Makefile.am:3: error: COVERALLS does not appear …
mkrufky Jun 1, 2016
1af7719
.travis.yml: temporarily disable build under clang 3.5 / 3.6
mkrufky Jun 1, 2016
b7f9bfb
libdvbtee/value/Makefile.am: remove unneeded "AM_CXXFLAGS = -I../incl…
mkrufky Jun 1, 2016
65bd48b
libdvbtee/value/value.pro: remove unneeded "DESTDIR = .."
mkrufky Jun 1, 2016
04920b5
object: fix returning pointer to local outside scope
mkrufky Jun 11, 2016
b3107de
handle: fix RESOURCE_LEAK issue found by the Coverity checker
mkrufky Jun 12, 2016
0d36222
handle: remove dead code depending on Object & Array
mkrufky Jun 13, 2016
5dd8b05
Merge branch 'master' into valobj-update
mkrufky Feb 10, 2017
3548f14
value/Makefile.am: replace accidentally removed handle.h
mkrufky Feb 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libdvbtee/value/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
lib_LTLIBRARIES = libvalueobj.la

libvalueobj_la_SOURCES = value.cpp object.cpp array.cpp
libvalueobj_la_SOURCES = value.cpp object.cpp array.cpp handle.cpp

EXTRA_DIST=value.h object.h array.h
EXTRA_DIST=value.h object.h array.h handle.h

VALOBJ_LIBRARY_VERSION=1:0:0

libvalueobj_la_LDFLAGS = -version-info $(VALOBJ_LIBRARY_VERSION)

library_includedir=$(includedir)/value
library_include_HEADERS = value.h object.h array.h
library_include_HEADERS = value.h object.h array.h handle.h
168 changes: 40 additions & 128 deletions libdvbtee/value/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,11 @@ using namespace valueobj;

namespace valueobj {

template <typename T>
const ValueBase* Array::push(T val)
{
return push<T>(val, "");
}

template <typename T>
const ValueBase* Array::set(std::string key, T val)
{
if (!key.length()) return NULL;
const ValueBase* v = push<T>(val, key);
if (v) updateIndex(key, v);
return v;
}

template <typename T>
const ValueBase* Array::set(int key, T val)
{
return set<T>(intToStr(key), val);
}

template <typename T>
const ValueBase* Array::pushByRef(T& val, std::string idx)
{
Value<T> *v = new Value<T>(idx, val);
vector.push_back(v);
++(*v); // increment refcount
return v;
}

template <typename T>
const ValueBase* Array::push(T val, std::string idx)
{
return pushByRef<T>(val, idx);
}


template <typename T>
const T& Array::get(unsigned int &idx, T& def) const
{
if (idx <= vector.size()) {
Value<T> *val = (Value<T>*)vector[idx];
Value<T> *val = vector.at(idx);
if (val->checkType(typeid(T)))
return val->get();
}
Expand All @@ -82,11 +45,9 @@ const T& Array::get(unsigned int &idx, T& def) const
}

#define IMPL_ARRAY_TMPL(T) \
template const ValueBase* Array::push(T val); \
template const ValueBase* Array::set(std::string key, T val); \
template const ValueBase* Array::set(int key, T val); \
template const ValueBase* Array::pushByRef(T& val, std::string idx); \
template const ValueBase* Array::push(T val, std::string idx); \
template Handle& Array::push(T val); \
template bool Array::set(std::string key, T val); \
template bool Array::set(int key, T val); \
template const T& Array::get(unsigned int &idx, T& def) const

IMPL_ARRAY_TMPL(int);
Expand All @@ -106,6 +67,7 @@ IMPL_ARRAY_TMPL(Array);
IMPL_ARRAY_TMPL(Object);

static ReferencedValueUndefined& valueUndefined = ReferencedValueUndefined::instance();
static Handle valueUndefinedHdl = Handle((ValueBase*)&valueUndefined);

Array::Array(std::string idx)
: idxField(idx)
Expand All @@ -126,16 +88,30 @@ Array::~Array()
Array::Array(const Array &obj)
{
for (KeyValueVector::const_iterator it = obj.vector.begin(); it != obj.vector.end(); ++it) {
ValueBase *v = *it;
push(v);
const std::string& n = v->getName();
if (n.length()) updateIndex(n, v);
Handle& hdl = push(*it);
const std::string& n = hdl.get()->getName();
if (n.length()) updateIndex(n, hdl);
}
#if DBG
fprintf(stderr, "%s(copy) %lu\n", __func__, vector.size());
#endif
}

Handle& Array::push(Handle hdl)
{
vector.push_back(hdl);
return vector.back();
}

bool Array::set(std::string key, Handle hdl)
{
if (!key.length()) return false;

Handle& h = push(hdl);
updateIndex(key, h);
return true;
}

const std::string Array::toJson() const
{
std::stringstream s;
Expand All @@ -147,7 +123,7 @@ const std::string Array::toJson() const
for (KeyValueVector::const_iterator it = vector.begin(); it != vector.end(); ++it) {
if (it != vector.begin()) s << ", ";

s << (*it)->toJson();
s << it->toJson();
}
s << " ]";

Expand All @@ -165,17 +141,17 @@ const std::string &Array::getIndex() const
return idxField;
}

const ValueBase* Array::get(unsigned int idx) const
Handle& Array::get(unsigned int idx) const
{
if (idx <= vector.size())
return vector[idx];
return (Handle&)vector.at(idx);

return &valueUndefined;
return valueUndefinedHdl;
}

void Array::updateIndex(std::string key, const ValueBase *val)
void Array::updateIndex(std::string key, Handle& val)
{
if (key.length()) indices[key] = val;
if (key.length()) indices[key] = &val;
}

std::string &Array::assignIndex(Object &obj, std::string &index)
Expand All @@ -189,27 +165,22 @@ std::string &Array::assignIndex(Object &obj, std::string &index)
return index;
}

const ValueBase* Array::getByName(std::string idx) const
Handle& Array::getByName(std::string idx) const
{
std::map<std::string, const ValueBase*>::const_iterator it = indices.find(idx);
std::map<std::string, Handle*>::const_iterator it = indices.find(idx);
if (it == indices.end())
return &valueUndefined;
return valueUndefinedHdl;

return it->second;
return *(it->second);
}

const ValueBase* Array::getByName(unsigned int idx) const
Handle& Array::getByName(unsigned int idx) const
{
return getByName(intToStr(idx));
}

void Array::clear()
{
for (KeyValueVector::iterator it = vector.begin(); it != vector.end(); ++it)
{
// decrement refcount. if refcount becomes zero, delete
if (0 == (--(**it)).getRefCnt()) delete *it;
}
vector.clear();
indices.clear();
}
Expand All @@ -221,91 +192,32 @@ const std::string Array::intToStr(int i) const
return s.str();
}

const ValueBase* Array::pushObject(Object &val, std::string idx)
Handle& Array::pushObject(Object &val, std::string idx)
{
bool extractIndex = (!idx.length());

if (extractIndex) assignIndex(val, idx);

const ValueBase *v = pushByRef<Object>(val, idx);
Handle& v = push(Handle(val, idx));

if (extractIndex) updateIndex(idx, v);

return v;
}

#ifndef USING_INLINE_PUSH
const ValueBase *Array::push(char *val, std::string idx)
{
return push<std::string>(std::string(val), idx);
}

const ValueBase *Array::push(const char *val, std::string idx)
{
return push<std::string>(std::string(val), idx);
}

const ValueBase *Array::push(std::string &val, std::string idx)
{
return pushByRef<std::string>(val, idx);
}

const ValueBase *Array::push(Array &val, std::string idx)
{
return pushByRef<Array>(val, idx);
}

const ValueBase *Array::push(Array *val, std::string idx)
{
return pushByRef<Array>(*val, idx);
}
#endif

const ValueBase* Array::push(Object &o)
Handle& Array::push(Object &o)
{
return pushObject(o, "");
}

const ValueBase *Array::push(Object *o)
Handle& Array::push(Object *o)
{
return push(*o);
}

const ValueBase* Array::push(char *val)
{
return push<std::string>(std::string(val));
}

const ValueBase* Array::push(const char *val)
{
return push<std::string>(std::string(val));
}

const ValueBase *Array::set(std::string key, char *val)
{
return set(key, std::string(val));
}

const ValueBase *Array::set(std::string key, const char *val)
{
return set(key, std::string(val));
}

const ValueBase *Array::set(int key, char *val)
{
return set(intToStr(key), val);
}

const ValueBase *Array::set(int key, const char *val)
{
return set(intToStr(key), val);
}

const ValueBase* Array::push(ValueBase *val)
Handle& Array::push(ValueBase *val)
{
vector.push_back(val);
++(*val);
return val;
return push(Handle(val));
}

DEFINE_DEFAULT_GETTERS(Array, unsigned int)
Expand Down
67 changes: 26 additions & 41 deletions libdvbtee/value/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

#include "value.h"
#include "object.h"
#include "handle.h"

namespace valueobj {

typedef std::vector<ValueBase*> KeyValueVector;
typedef std::vector<Handle> KeyValueVector;

class Object;

Expand All @@ -42,33 +43,38 @@ class Array {

Array(const Array&);

const ValueBase* push(ValueBase*);
Handle& push(Handle hdl);

const ValueBase* push(Object&);
const ValueBase* push(Object*);
Handle& push(ValueBase*);

Handle& push(Object&);
Handle& push(Object*);

template <typename T>
const ValueBase* push(T val);
Handle& push(T val)
{
return push(Handle(val, ""));
}

const ValueBase* push( char* val);
const ValueBase* push(const char* val);
bool set(std::string key, Handle hdl);

template <typename T>
const ValueBase* set(std::string key, T val);

const ValueBase* set(std::string key, char* val);
const ValueBase* set(std::string key, const char* val);
bool set(std::string key, T val)
{
return set(key, Handle(val, key));
}

template <typename T>
const ValueBase* set(int key, T val);
bool set(int key, T val)
{
return set(intToStr(key), val);
}

const ValueBase* set(int key, char* val);
const ValueBase* set(int key, const char* val);

const ValueBase* getByName(std::string idx) const;
const ValueBase* getByName(unsigned int idx) const;
Handle& getByName(std::string idx) const;
Handle& getByName(unsigned int idx) const;

const ValueBase* get(unsigned int idx) const;
Handle& get(unsigned int idx) const;

template <typename T> const T& get(unsigned int idx) const;

Expand All @@ -82,36 +88,15 @@ class Array {

private:
KeyValueVector vector;
std::map<std::string, const ValueBase*> indices;
std::map<std::string, Handle*> indices;
std::string idxField;

template <typename T>
const ValueBase* pushByRef(T& val, std::string idx);

const ValueBase* pushObject(Object& val, std::string idx);

template <typename T>
const ValueBase* push(T val, std::string idx);

#define USING_INLINE_PUSH
#ifdef USING_INLINE_PUSH
inline const ValueBase* push( char* val, std::string idx) { return push<std::string>(std::string(val), idx); }
inline const ValueBase* push(const char* val, std::string idx) { return push<std::string>(std::string(val), idx); }
inline const ValueBase* push(std::string& val, std::string idx) { return pushByRef<std::string>(val, idx); }
inline const ValueBase* push(Array& val, std::string idx) { return pushByRef<Array>(val, idx); }
inline const ValueBase* push(Array* val, std::string idx) { return pushByRef<Array>(*val, idx); }
#else
const ValueBase* push( char* val, std::string idx);
const ValueBase* push(const char* val, std::string idx);
const ValueBase* push(std::string& val, std::string idx);
const ValueBase* push(Array& val, std::string idx);
const ValueBase* push(Array* val, std::string idx);
#endif
Handle& pushObject(Object& val, std::string idx);

template <typename T>
const T& get(unsigned int &idx, T& def) const;

void updateIndex(std::string, const ValueBase*);
void updateIndex(std::string, Handle&);
std::string& assignIndex(Object&, std::string&);

const std::string intToStr(int) const;
Expand Down
Loading