Qore Programming Language 1.19.2
Loading...
Searching...
No Matches
GlobalVariableList.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 QoreProgram.h
4
5 Program QoreObject Definition
6
7 Qore Programming Language
8
9 Copyright (C) 2003 - 2023 Qore Technologies, s.r.o.
10
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the "Software"),
13 to deal in the Software without restriction, including without limitation
14 the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 and/or sell copies of the Software, and to permit persons to whom the
16 Software is furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28
29 Note that the Qore library is released under a choice of three open-source
30 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31 information.
32*/
33
34#ifndef _QORE_GLOBALVARIABLELIST_H
35
36#define _QORE_GLOBALVARIABLELIST_H
37
38#include "qore/intern/Variable.h"
39
40class Var;
41
42// we use a vector map as the number of constants is generally relatively small
43#include <qore/vector_map>
44typedef vector_map_t<const char*, Var*> map_var_t;
45/*
46#ifdef HAVE_QORE_HASH_MAP
47//#warning compiling with hash_map
48#include <qore/hash_map_include.h>
49#include "qore/intern/xxhash.h"
50
51typedef HASH_MAP<const char*, Var*, qore_hash_str, eqstr> map_var_t;
52#else
53#include <map>
54typedef std::map<const char*, Var*, ltstr> map_var_t;
55#endif
56*/
57
58// this is a "grow-only" container
59// all reading and writing is done within the parse lock on the containing program object
60class GlobalVariableList {
61protected:
62
63public:
64 map_var_t vmap;
65
66 DLLLOCAL GlobalVariableList() {
67 }
68
69 DLLLOCAL GlobalVariableList(const GlobalVariableList& old, int64 po);
70
71 DLLLOCAL void mergePublic(const GlobalVariableList& old);
72
73 DLLLOCAL ~GlobalVariableList() {
74 reset();
75 assert(vmap.empty());
76 }
77
78 DLLLOCAL void clearAll(ExceptionSink *xsink);
79 DLLLOCAL void deleteAll(ExceptionSink* xsink);
80
81 // called at runtime
82 // returns a non-0 Var* if a new variable was created, 0 if not (because it already existed - exception raised)
83 DLLLOCAL Var* import(Var* var, ExceptionSink* xsink, bool readonly = false);
84
85 DLLLOCAL Var* runtimeCreateVar(const char* name, const QoreTypeInfo* typeInfo, bool builtin = false);
86
87 DLLLOCAL Var* parseFindVar(const char* name);
88 DLLLOCAL Var* parseCreatePendingVar(const QoreProgramLocation* loc, const char* name, const QoreTypeInfo* typeInfo);
89 DLLLOCAL const Var* parseFindVar(const char* name) const;
90
91 DLLLOCAL void parseAdd(Var* v);
92
93 // xxx DLLLOCAL Var* parseFindCreateVar(const char* name, QoreParseTypeInfo* typeInfo, bool& new_var);
94 // xxx DLLLOCAL Var* parseFindCreateVar(const char* name, const QoreTypeInfo* typeInfo, bool& new_var);
95
96 DLLLOCAL Var* runtimeFindVar(const char* name) const {
97 map_var_t::const_iterator i = vmap.find(name);
98 return i != vmap.end() ? i->second : nullptr;
99 }
100
101 DLLLOCAL QoreListNode* getVarList() const;
102
103 DLLLOCAL void getGlobalVars(const std::string& path, QoreHashNode& h) const;
104
105 DLLLOCAL int parseInit();
106 DLLLOCAL void reset();
107};
108
109#endif
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260