Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/debugger/engine/tydesc-factory.cxx
ViewVC logotype

Diff of /branches/vis15/src/debugger/engine/tydesc-factory.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5125, Wed Jul 19 18:32:51 2017 UTC revision 5126, Wed Jul 19 21:04:31 2017 UTC
# Line 10  Line 10 
10   * All rights reserved.   * All rights reserved.
11   */   */
12    
13  #include "json.hxx"  #include "tydesc-factory.hxx"
14  #include "typedesc.hxx"  #include <functional>
15    #include <unordered_map>
16    
17    // instantiate std::hash for JSON values
18    template<>
19    struct std::hash<JSON::value> {
20        size_t operator()(JSON::value const &v) { return v.hash(); }
21    };
22    
23    namespace DDebug {
24    
25        struct hash_json {
26            size_t operator()(JSON::value const *v) const { return v->hash(); }
27        };
28    
29        struct eql_json {
30            bool operator()(JSON::value const *lhs, JSON::value const *rhs) const
31            {
32                return true;
33            }
34        };
35    
36        typedef std::unordered_map<const JSON::value *, const type_desc *, hash_json, eql_json> json_map;
37    
38        struct hash_table {
39            json_map _tbl;
40    
41            hash_table () : _tbl(100) { }
42    
43            const type_desc *find (JSON::value const &desc) const
44            {
45                json_map::const_iterator got = _tbl.find(&desc);
46                if (got == this->_tbl.end()) {
47                    return nullptr;
48                }
49                else {
50                    return got->second;
51                }
52            }
53    
54        };
55    
56      /********** class tydesc_factory members **********/
57    
58        tydesc_factory::tydesc_factory (bool longInt, bool doubleReal)
59          : _longInt(longInt), _doubleReal(doubleReal), _tbl(new hash_table())
60        { }
61    
62        tydesc_factory::~tydesc_factory () { delete this->_tbl; }
63    
64    /* TODO
65        type_desc *tydesc_factory::mk_bool_tydesc ();
66        type_desc *tydesc_factory::mk_int_tydesc ();
67        type_desc *tydesc_factory::mk_string_tydesc ();
68    */
69    
70        const type_desc *tydesc_factory::mk_tydesc (JSON::value const &desc)
71        {
72            return this->_tbl->find (desc); /* FIXME */
73        }
74    
75    }

Legend:
Removed from v.5125  
changed lines
  Added in v.5126

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0