~ubuntu-branches/ubuntu/saucy/qt-gstreamer/saucy-proposed

« back to all changes in this revision

Viewing changes to src/QGlib/value.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2012-06-15 15:03:26 UTC
  • mfrom: (1.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120615150326-pkmdog620pkytcgt
Tags: 0.10.2-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Enable unit tests.
    + Build-depend on gstreamer0.10-plugins-base.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    This program is distributed in the hope that it will be useful,
12
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
    GNU General Public License for more details.
 
14
    GNU Lesser General Public License for more details.
15
15
 
16
16
    You should have received a copy of the GNU Lesser General Public License
17
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
292
292
    s_dispatcher()->setVTable(type, vtable);
293
293
}
294
294
 
 
295
static inline std::string toStdStringHelper(const QString & str)
 
296
{
 
297
#ifndef QT_NO_STL
 
298
    return str.toStdString();
 
299
#else
 
300
    const QByteArray asc = str.toAscii();
 
301
    return std::string(asc.constData(), asc.length());
 
302
#endif
 
303
}
 
304
 
295
305
void Value::getData(Type dataType, void *data) const
296
306
{
297
307
    if (!isValid()) {
301
311
        if (vtable.get != NULL) {
302
312
            vtable.get(*this, data);
303
313
        } else {
304
 
            throw Private::UnregisteredTypeException(dataType.name().toStdString());
 
314
            throw Private::UnregisteredTypeException(toStdStringHelper(dataType.name()));
305
315
        }
306
316
    } else if (dataType.isValueType() && g_value_type_transformable(type(), dataType)) {
307
317
        Value v;
308
318
        v.init(dataType);
309
319
 
310
320
        if (!g_value_transform(d->value(), v.d->value())) {
311
 
            throw Private::TransformationFailedException(type().name().toStdString(),
312
 
                                                         dataType.name().toStdString());
 
321
            throw Private::TransformationFailedException(toStdStringHelper(type().name()),
 
322
                                                         toStdStringHelper(dataType.name()));
313
323
        }
314
324
 
315
325
        v.getData(dataType, data);
316
326
    } else {
317
 
        throw Private::InvalidTypeException(dataType.name().toStdString(),
318
 
                                            type().name().toStdString());
 
327
        throw Private::InvalidTypeException(toStdStringHelper(dataType.name()),
 
328
                                            toStdStringHelper(type().name()));
319
329
    }
320
330
}
321
331
 
328
338
        if (vtable.set != NULL) {
329
339
            vtable.set(*this, data);
330
340
        } else {
331
 
            throw Private::UnregisteredTypeException(dataType.name().toStdString());
 
341
            throw Private::UnregisteredTypeException(toStdStringHelper(dataType.name()));
332
342
        }
333
343
    } else if (dataType.isValueType() && g_value_type_transformable(dataType, type())) {
334
344
        Value v;
336
346
        v.setData(dataType, data);
337
347
 
338
348
        if (!g_value_transform(v.d->value(), d->value())) {
339
 
            throw Private::TransformationFailedException(dataType.name().toStdString(),
340
 
                                                         type().name().toStdString());
 
349
            throw Private::TransformationFailedException(toStdStringHelper(dataType.name()),
 
350
                                                         toStdStringHelper(type().name()));
341
351
        }
342
352
    } else {
343
 
        throw Private::InvalidTypeException(dataType.name().toStdString(),
344
 
                                            type().name().toStdString());
 
353
        throw Private::InvalidTypeException(toStdStringHelper(dataType.name()),
 
354
                                            toStdStringHelper(type().name()));
345
355
    }
346
356
}
347
357