aboutsummaryrefslogtreecommitdiff
path: root/c++-qt/src/object.cpp
blob: b0f0f1235be7f49fab819566b2e0e24fa2c51bea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "gats-qt/object.h"

#include "gats-qt/integer.h"
#include "gats-qt/float.h"
#include "gats-qt/boolean.h"
#include "gats-qt/string.h"
#include "gats-qt/list.h"
#include "gats-qt/dictionary.h"
#include "gats-qt/null.h"

#include "gats-qt/parseexception.h"

#include <stdlib.h>

#include <QIODevice>

Gats::Object::Object()
{
}

Gats::Object::~Object()
{
}

Gats::Object *Gats::Object::read( QIODevice &rIn )
{
    char buf;
    rIn.read( &buf, 1 );
    Object *pObj = NULL;
    switch( buf )
    {
        case 'i':
            pObj = new Gats::Integer();
            break;

        case 's':
            pObj = new Gats::String();
            break;

        case '0':
        case '1':
            pObj = new Gats::Boolean();
            break;

        case 'l':
            pObj = new Gats::List();
            break;

        case 'd':
            pObj = new Gats::Dictionary();
            break;

        case 'f':  // Normal floats
        case 'F':  // Special float values
            pObj = new Gats::Float();
            break;

        case 'n':
            pObj = new Gats::Null();
            break;

        case 'e':
            return NULL;

        default:
            throw ParseException("Invalid Gats type discovered.");
    }

    pObj->read( rIn, buf );

    return pObj;
}

const char *Gats::typeToStr( Gats::Type t )
{
    switch( t )
    {
        case Gats::typeDictionary:  return "dictionary";
        case Gats::typeList:        return "list";
        case Gats::typeString:      return "string";
        case Gats::typeInteger:     return "integer";
        case Gats::typeFloat:       return "float";
        case Gats::typeBoolean:     return "boolean";
        case Gats::typeNull:        return "null";
    }

    return "***unknown***";
}