1 /* collection.h                                           -*- coding: utf-8; -*-
2  *
3  *   Copyright (c) 2010-2021  Takashi Kato <ktakashi@ymail.com>
4  *
5  *   Redistribution and use in source and binary forms, with or without
6  *   modification, are permitted provided that the following conditions
7  *   are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above copyright
13  *      notice, this list of conditions and the following disclaimer in the
14  *      documentation and/or other materials provided with the distribution.
15  *
16  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *  $Id: $
29  */
30 #ifndef SAGITTARIUS_PRIVATE_COLLECTION_H_
31 #define SAGITTARIUS_PRIVATE_COLLECTION_H_
32 
33 /* definition of collections */
34 #include "sagittariusdefs.h"
35 #include "clos.h"
36 
37 SG_CLASS_DECL(Sg_CollectionClass);
38 SG_CLASS_DECL(Sg_SequenceClass);
39 SG_CLASS_DECL(Sg_DictionaryClass);
40 SG_CLASS_DECL(Sg_OrderedDictionaryClass);
41 
42 #define SG_CLASS_COLLECTION 	    (&Sg_CollectionClass)
43 #define SG_CLASS_SEQUENCE   	    (&Sg_SequenceClass)
44 #define SG_CLASS_DICTIONARY 	    (&Sg_DictionaryClass)
45 #define SG_CLASS_ORDERED_DICTIONARY (&Sg_OrderedDictionaryClass)
46 
47 extern SgClass *Sg__OrderedDictionaryCPL[];
48 extern SgClass *Sg__SequenceCPL[];
49 
50 #define SG_CLASS_COLLECTION_CPL 	(Sg__SequenceCPL+1)
51 #define SG_CLASS_SEQUENCE_CPL   	(Sg__SequenceCPL)
52 #define SG_CLASS_DICTIONARY_CPL 	(Sg__OrderedDictionaryCPL+2)
53 #define SG_CLASS_ORDERED_DICTIONARY_CPL (Sg__OrderedDictionaryCPL)
54 
55 typedef struct SgDictEntryRec
56 {
57   intptr_t key;
58   intptr_t value;
59 } SgDictEntry;
60 
61 typedef enum SgDictOpRec {
62   SG_DICT_GET,
63   SG_DICT_CREATE,
64   SG_DICT_DELETE
65 } SgDictOp;
66 
67 typedef enum {
68   SG_DICT_NO_OVERWRITE = (1L<<0), /* do not overwrite the existing entry */
69   SG_DICT_NO_CREATE    = (1L<<1), /* do not create new one if no match */
70   SG_DICT_ON_COPY      = (1L<<2)  /* [Internal use only] */
71 } SgDictSetFlags;
72 
73 #define SG_DICT_ENTRY_KEY(e)   SG_OBJ((e)->key)
74 #define SG_DICT_ENTRY_VALUE(e) SG_OBJ((e)->value)
75 #define SG_DICT_ENTRY_SET_VALUE(e, v)		\
76   SG_OBJ((e)->value = (intptr_t)v)
77 
78 
79 
80 #endif /* SAGITTARIUS_COLLECTION_H_ */
81