32#ifndef _QORE_INTERN_TYPED_HASH_DECL_PRIVATE_H
34#define _QORE_INTERN_TYPED_HASH_DECL_PRIVATE_H
36#include "qore/intern/QoreClassIntern.h"
40class typed_hash_decl_private;
42class HashDeclMemberInfo :
public QoreMemberInfoBase {
44 DLLLOCAL HashDeclMemberInfo(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeInfo =
nullptr,
46 : QoreMemberInfoBase(loc, n_typeInfo, n_parseTypeInfo, e) {
49 DLLLOCAL HashDeclMemberInfo(
const HashDeclMemberInfo& old) : QoreMemberInfoBase(old) {
52 DLLLOCAL
bool equal(
const HashDeclMemberInfo& other)
const;
54 DLLLOCAL
int parseInit(
const char* name,
bool priv);
57typedef QoreMemberMapBase<HashDeclMemberInfo> HashDeclMemberMap;
59class typed_hash_decl_private {
60friend class typed_hash_decl_member_iterator;
63 DLLLOCAL typed_hash_decl_private(
const QoreProgramLocation* loc) : loc(loc), orig(this) {
67 DLLLOCAL typed_hash_decl_private(
const QoreProgramLocation* loc,
const char* n,
const char* p,
69 loc(loc), name(n), path(p), thd(thd), orig(this),
70 typeInfo(new QoreHashDeclTypeInfo(thd, n, p)),
71 orNothingTypeInfo(new QoreHashDeclOrNothingTypeInfo(thd, n, p)) {
75 DLLLOCAL typed_hash_decl_private(
const typed_hash_decl_private& old,
TypedHashDecl* thd);
77 DLLLOCAL ~typed_hash_decl_private() {
79 delete orNothingTypeInfo;
86 path = get_ns_path(n);
91 DLLLOCAL
bool equal(
const typed_hash_decl_private& other)
const {
92 if (name != other.name || members.size() != other.members.size())
95 for (HashDeclMemberMap::const_iterator ti = members.member_list.begin(), oi = other.members.member_list.begin(),
96 te = members.member_list.end(); ti != te; ++ti, ++oi) {
98 if (strcmp(oi->first, ti->first)) {
102 if (!ti->second->equal(*oi->second)) {
110 DLLLOCAL
bool parseEqual(
const typed_hash_decl_private& other)
const {
111 const_cast<typed_hash_decl_private*
>(
this)->parseInit();
115 DLLLOCAL
const QoreTypeInfo* getTypeInfo(
bool or_nothing =
false)
const {
116 return or_nothing ? orNothingTypeInfo : typeInfo;
119 DLLLOCAL
bool isPublic()
const {
123 DLLLOCAL
bool isUserPublic()
const {
127 DLLLOCAL
void setPublic() {
132 DLLLOCAL
void setPrivate() {
137 DLLLOCAL
bool isSystem()
const {
141 DLLLOCAL
void ref()
const {
145 DLLLOCAL
bool deref() {
146 if (refs.ROdereference()) {
153 DLLLOCAL
int parseInit() {
154 if (parse_init_done || sys) {
157 parse_init_done =
true;
162 for (
auto& i : members.member_list) {
164 if (i.second->parseInit(i.first,
true) && !err) {
174 DLLLOCAL
int parseInitHashDeclInitialization(
const QoreProgramLocation* loc, QoreParseContext& parse_context,
175 QoreParseListNode* args,
bool& runtime_check)
const;
177 DLLLOCAL
int parseCheckHashDeclInitialization(
const QoreProgramLocation* loc,
const QoreTypeInfo* expTypeInfo,
178 QoreValue exp,
const char* context_action,
bool& runtime_check,
bool strict_check =
true)
const;
180 DLLLOCAL
int parseCheckHashDeclAssignment(
const QoreProgramLocation* loc,
const typed_hash_decl_private& hd,
181 const char* context,
bool& needs_runtime_check,
bool strict_check =
true)
const;
183 DLLLOCAL
int parseCheckHashDeclAssignment(
const QoreProgramLocation* loc,
QoreValue n,
const char* context,
184 bool& needs_runtime_check,
bool strict_check =
true)
const;
186 DLLLOCAL
int parseCheckComplexHashAssignment(
const QoreProgramLocation* loc,
const QoreTypeInfo* vti)
const;
195 const HashDeclMemberInfo* mem = members.find(key);
197 xsink->
raiseException(
"HASHDECL-KEY-ERROR",
"cannot assign unknown key '%s' to hashdecl '%s'", key, name.c_str());
200 QoreTypeInfo::acceptInputKey(mem->getTypeInfo(), key, *val, xsink);
208 DLLLOCAL
int parseCheckMemberAccess(
const QoreProgramLocation* loc,
const char* mem,
209 const QoreTypeInfo*& memberTypeInfo,
int pflag)
const;
211 DLLLOCAL
const HashDeclMemberInfo* findMember(
const char* m)
const {
212 return members.find(m);
215 DLLLOCAL
void parseAdd(std::pair<char*, HashDeclMemberInfo*> pair) {
216 members.addNoCheck(pair);
219 DLLLOCAL
bool hasMember(
const char* name)
const {
220 return members.inList(name);
223 DLLLOCAL
void setSystemPublic() {
230 DLLLOCAL
const char* getName()
const {
234 DLLLOCAL
const char* getPath()
const {
238 DLLLOCAL
const std::string& getNameStr()
const {
242 DLLLOCAL
const QoreProgramLocation* getParseLocation()
const {
246 DLLLOCAL
static typed_hash_decl_private* get(
TypedHashDecl& hashdecl) {
247 return hashdecl.priv;
250 DLLLOCAL
static const typed_hash_decl_private* get(
const TypedHashDecl& hashdecl) {
251 return hashdecl.priv;
254 DLLLOCAL
void addMember(
const char* name,
const QoreTypeInfo* memberTypeInfo,
QoreValue init_val) {
255 assert(!members.find(name));
256 members.addNoCheck(std::make_pair(strdup(name),
new HashDeclMemberInfo(&loc_builtin, memberTypeInfo,
nullptr, init_val)));
259 DLLLOCAL
void setName(
const char* n) {
263 DLLLOCAL
const HashDeclMemberMap& getMembers()
const {
267 DLLLOCAL
const HashDeclMemberInfo* findLocalMember(
const char* name)
const {
268 return members.find(name);
271 DLLLOCAL
void setNamespace(qore_ns_private* n) {
275 DLLLOCAL
const qore_ns_private* getNamespace()
const {
279 DLLLOCAL
const char* getModuleName()
const {
280 return from_module.empty() ? nullptr : from_module.c_str();
286 const QoreProgramLocation* loc;
291 qore_ns_private* ns =
nullptr;
293 std::string from_module;
296 const typed_hash_decl_private* orig;
299 QoreHashDeclTypeInfo* typeInfo =
nullptr;
300 QoreHashDeclOrNothingTypeInfo* orNothingTypeInfo =
nullptr;
303 HashDeclMemberMap members;
308 bool parse_init_done =
false;
310 DLLLOCAL
void assignModule() {
311 const char* mod_name = get_module_context_name();
313 from_module = mod_name;
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
DLLEXPORT int appendLastDescription(const char *fmt,...)
appends a formatted string to the top exception description if the desc value is a string
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
typed hash declaration
Definition: TypedHashDecl.h:44
holds an object and dereferences it in the destructor
Definition: QoreValue.h:487
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276