Qore Programming Language Reference Manual  1.10.0
Hashdecl: Type-Safe Hash Declarations

Type-Safe Hashes Overview

The hashdecl keyword allows for type-safe hashes to be declared; they can then be instantiated with the new operator, the cast<> operator, or with variable implicit construction.

hashdecl Declaration Syntax

hashdecl hashdecl_identifier {
    member_type member_name [= initialization_expression];
    [...]
}

At least one member must be defined; it's not possible to declare an empty type-safe hash.

Example
hashdecl MyHash {
int i = 1;
string code = "other";
}
Note
  • a hashdecl may not have the name "auto", this name has a special meaning in complex types
  • Each Qore type has a "pseudo-class" associated with it; for hashes the type is <hash>; methods from the data type's "pseudo-class" can be run on any value of that type.

Type-Safe Hash Creation

When type-safe hashes are created, the hash is automatically populated with the values given by the initialization expressions in the hashdecl declaration (if any).

It is possible to override these declarations by passing a hash to be used for initialization; this can be passed the single optional argument to the type-safe hash initialization as in the following examples:

Examples
# type-safe hash declaration
hashdecl Container {
int i = 1;
}
# immediate value with implicit construction: default values are assigned from the declaration
auto ah1 = hash<Container>{};
# immediate value with implicit construction: default values are assigned from the declaration
auto ah2 = <Container>{};
# immediate value with implicit construction: overrides the "i" member's initial value
auto ah3 = <Container>{"i": 2};
# implicit construction: default values are assigned from the declaration
hash<Container> h1();
# implicit construction: overrides the "i" member's initial value
hash<Container> h2(("i": 2));
# "new" construction: default values are assigned from the declaration
hash<Container> h3 = new hash<Container>();
# "class="el" href="struct_data_provider_1_1_allowed_value_info.html" target="_self">AllowedValueInfoAllowed value hash  CDataFieldInfoDescribes a data type  CDataProviderData provider class  CDataProviderBulkRecordIteratorDefines the standard record iterator for bulk record iterators  CDataProviderExpressionData provider expression  CDataProviderExpressionInfoData provider signature info  CDataProviderFactoryInfoData provider factory info  CDataProviderFieldReferenceData provider field reference  CDataProviderInfoData provider info  CDataProviderMessageInfoData provider message and event info  CDataProviderOptionInfoData provider option info  CDataProviderPipelineDefines a class for passing data through record processors  CDataProviderPipelineFactoryA factory class for creating DataProviderPipeline objects  CDataProviderSignatureTypeInfoData provider signature argument info  CDataProviderSummaryInfoData provider summary info  CDataProviderTypeCacheData provider type cache class  CDataProviderTypeEntryDataProviderTypeEntry class  CDataProviderTypeEntryInfoData provider type entry info  CDataProviderTypeOptionInfoDescribes type options  CDataTypeInfoDescribes a data type  CDefaultBulkInserterDefault builk inserter class  CDefaultBulkRecordIterfaceDefault bulk record interface class for data providers that do not support bulk read APIs  CDefaultBulkUpserterDefault builk inserter class  CDefaultRecordIteratorDefault record iterator class for data providers that do not support custom read / search APIs  CDelayedObservableThis class represents an observable subject that waits for external confirmation before raising events  CHashDataTypeDescribes a data type based on a hash  CHashDeclDataTypeDescribes a data type based on a hashdecl  CListDataTypeDescribes a data type based on a hash  CNullDataProviderA dumrequest data provider that provides an empty hash as the request and response types  CNullDataProviderFactoryThe null data provider factory  CObservableThis class represents an observable subject that will notify all of its registered observers  CObserverThis abstract class represents an observer that will get notified by the subject it observes  CPipelineFactoryInfoPipeline factory info  CPipelineInfoPipeline info  CPipelineOptionInfoPipeline option info  CPipelineQueuePipeline element  CQoreBinaryDataTypeDescribes a data type based on binary  CQoreBinaryDataTypeBaseDescribes a data type based on binary types with validation for parsing strings when used with soft types  CQoreBinaryOrNothingDataTypeDescribes a data type based on *binary  CQoreBoolDataTypeDescribes a data type based on int  CQoreBoolDataTypeBaseDescribes a data type based on softint with validation for parsing strings  CQoreBoolOrNothingDataTypeDescribes a data type based on *int  CQoreDataFieldDescribes a data type based on a hashdecl  CQoreDataTypeDescribes a data type based on a Qore data type  CQoreDateDataTypeDescribes a data type based on date with output time zone support  CQoreDateDataTypeBaseDescribes a data type based on a date type with validation for string parsing and time zone support  CQoreDateOrNothingDataTypeDescribes a data type based on softdate with validation for string parsing and time zone support  CQoreFloatDataTypeDescribes a data type based on float  CQoreFloatDataTypeBaseDescribes a data type based on softnumber with validation for parsing strings  CQoreFloatOrNothingDataTypeDescribes a data type based on *float  CQoreHashDataTypeDescribes a data type  CQoreIntDataTypeDescribes a data type based on int  CQoreIntDataTypeBaseDescribes a data type based on int types with validation for parsing strings when used with soft types  CQoreIntOrNothingDataTypeDescribes a data type based on *int  CQoreListDataTypeDescribes a data type based on a hash  CQoreNumberDataTypeDescribes a data type based on number  CQoreNumberDataTypeBaseDescribes a data type based on number types with validation for parsing strings when used with soft types  CQoreNumberOrNothingDataTypeDescribes a data type based on *number  CQoreSoftBinaryDataTypeDescribes a data type based on softbinary with validation for parsing strings  CQoreSoftBinaryNoNullDataTypeDescribes a data type based on softbinary with validation for parsing strings  CQoreSoftBinaryOrNothingDataTypeDescribes a data type based on *softbinary with validation for parsing strings  CQoreSoftBoolDataTypeDescribes a data type based on softint with validation for parsing strings  CQoreSoftBoolNoNullDataTypeDescribes a data type based on softint with validation for parsing strings  CQoreSoftBoolOrNothingDataTypeDescribes a data type based on *softint with validation for parsing strings  CQoreSoftDateDataTypeDescribes a data type based on softdate with validation for string parsing and time zone support  CQoreSoftDateNoNullDataTypeDescribes a data type based on softdate with validation for string parsing and time zone support  CQoreSoftDateOrNothingDataTypeDescribes a data type based on softdate with validation for string parsing and time zone support  CQoreSoftFloatDataTypeDescribes a data type based on softfloat with validation for parsing strings  CQoreSoftFloatNoNullDataTypeDescribes a data type based on softfloat with validation for parsing strings  CQoreSoftFloatOrNothingDataTypeDescribes a data type based on *softfloat with validation for parsing strings  CQoreSoftIntDataTypeDescribes a data type based on softint with validation for parsing strings  CQoreSoftIntNoNullDataTypeDescribes a data type based on softint with validation for parsing strings  CQoreSoftIntOrNothingDataTypeDescribes a data type based on *softint with validation for parsing strings  CQoreSoftNumberDataTypeDescribes a data type based on softnumber with validation for parsing strings  CQoreSoftNumberNoNullDataTypeDescribes a data type based on softnumber with validation for parsing strings  CQoreSoftNumberOrNothingDataTypeDescribes a data type based on *softnumber with validation for parsing strings  CQoreSoftStringDataTypeDescribes a data type based on softstring with a target encoding  CQoreSoftStringOrNothingDataTypeDescribes a data type based on *softstring with a target encoding  CQoreStringDataTypeDescribes a data type based on string with a target encoding  CQoreStringDataTypeBaseDescribes a data type based on a string tyoe with a target encoding option  CQoreStringOrNothingDataTypeDescribes a data type based on *string with a target encoding  CSearchOperatorInfoGeneric operator info hash as returned by all generic search operator functions  CSoftListDataTypeDescribes a data type based on a hash