aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/dictionary.h
blob: 84cf69f9f6fc5d7c66254a6d1c145593644066aa (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
/*
 * 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.
 */

#ifndef GATS_DICTIONARY_H
#define GATS_DICTIONARY_H

#include "gats/object.h"
#include "gats/string.h"
#include <bu/hash.h>

namespace Gats
{
    class List;

    class Dictionary : public Gats::Object,
        public Bu::Hash<Gats::String, Gats::Object *>
    {
    public:
        Dictionary();
        virtual ~Dictionary();

        virtual Type getType() const { return typeDictionary; }
        Type getType( const Bu::String &sKey ) const;
        virtual Object *clone() const;      
        virtual void write( Bu::Stream &rOut ) const;
        virtual void read( Bu::Stream &rIn, char cType );

        void insert( const Bu::String &sKey, const char *s );
        void insert( const Bu::String &sKey, const Bu::String &s );
        void insert( const Bu::String &sKey, char i );
        void insert( const Bu::String &sKey, unsigned char i );
        void insert( const Bu::String &sKey, signed char i );
        void insert( const Bu::String &sKey, unsigned short i );
        void insert( const Bu::String &sKey, signed short i );
        void insert( const Bu::String &sKey, unsigned int i );
        void insert( const Bu::String &sKey, signed int i );
        void insert( const Bu::String &sKey, unsigned long i );
        void insert( const Bu::String &sKey, signed long i );
        void insert( const Bu::String &sKey, unsigned long long i );
        void insert( const Bu::String &sKey, signed long long i );
        //void insert( const Bu::String &sKey, bool b );
        void insert( const Bu::String &sKey, float d );
        void insert( const Bu::String &sKey, double d );
        using Bu::Hash<Gats::String, Gats::Object *>::insert;
        void insertBool( const Bu::String &sKey, bool b );
        void insertInt( const Bu::String &sKey, int64_t i );
        void insertFloat( const Bu::String &sKey, double d );
        void insertStr( const Bu::String &sKey, const Bu::String &s );
        void insertList( const Bu::String &sKey, Gats::List *pL );
        void insertDict( const Bu::String &sKey, Gats::Dictionary *pD );
        Gats::List *insertList( const Bu::String &sKey );
        Gats::Dictionary *insertDict( const Bu::String &sKey );
        void insertNull( const Bu::String &sKey );

        bool isNull( const Bu::String &sKey );
        bool getBool( const Bu::String &sKey );
        int64_t getInt( const Bu::String &sKey );
        double getFloat( const Bu::String &sKey );
        Bu::String getStr( const Bu::String &sKey );
        Gats::List *getList( const Bu::String &sKey );
        Gats::Dictionary *getDict( const Bu::String &sKey );
        
        bool isNull( const Bu::String &sKey ) const;
        bool getBool( const Bu::String &sKey ) const;
        int64_t getInt( const Bu::String &sKey ) const;
        double getFloat( const Bu::String &sKey ) const;
        Bu::String getStr( const Bu::String &sKey ) const;
        Gats::List *getList( const Bu::String &sKey ) const;
        Gats::Dictionary *getDict( const Bu::String &sKey ) const;
    };
};

namespace Bu
{
template<>
uint32_t __calcHashCode<Gats::String>( const Gats::String &s );
};

Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d );

#endif