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

SCM Repository

[diderot] Annotation of /branches/vis12/src/include/Diderot/dyn-seq.h
ViewVC logotype

Annotation of /branches/vis12/src/include/Diderot/dyn-seq.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (view) (download) (as text)

1 : jhr 1691 /*! \file dyn-seq.h
2 :     *
3 :     * \author John Reppy
4 :     */
5 :    
6 :     /*
7 : jhr 3291 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
8 :     *
9 :     * COPYRIGHT (c) 2015 The University of Chicago
10 : jhr 1691 * All rights reserved.
11 :     */
12 :    
13 :     #ifndef _DIDEROT_DYN_SEQ_H_
14 :     #define _DIDEROT_DYN_SEQ_H_
15 :    
16 :     typedef struct {
17 : jhr 1733 unsigned int base; //!< data[base] is the first element in the sequence
18 :     unsigned int nElems; //!< number of elements in the sequence
19 :     unsigned int size; //!< size of data buffer in elements
20 : jhr 1714 void *data; //!< pointer to underlying data buffer
21 : jhr 1691 } Diderot_DynSeq_t;
22 :    
23 :     #define DYNSEQ_SUB(ty, seq, i) (*((ty *)Diderot_DynSeqAddr(sizeof(ty), seq, i)))
24 :     #define DYNSEQ_MK(ty, n, data) Diderot_DynSeqMk(sizeof(ty), n, data)
25 :    
26 : jhr 1733 STATIC_INLINE unsigned int Diderot_DynSeqLength (Diderot_DynSeq_t *seq)
27 : jhr 1714 {
28 :     return seq->nElems;
29 :     }
30 :    
31 : jhr 1733 STATIC_INLINE Diderot_DynSeq_t *Diderot_DynSeqAlloc (size_t elemSz, int initialSz)
32 : jhr 1691 {
33 :     Diderot_DynSeq_t *seq = NEW(Diderot_DynSeq_t);
34 :     seq->base = 0;
35 :     seq->nElems = initialSz;
36 : jhr 1733 seq->size = initialSz + 8; // FIXME: be smarter about padding
37 : jhr 1691 seq->data = CheckedAlloc (elemSz * seq->size);
38 :     return seq;
39 :     }
40 :    
41 : jhr 1733 STATIC_INLINE Diderot_DynSeq_t *Diderot_DynSeqMk (size_t elemSz, int nElems, void *elems)
42 : jhr 1691 {
43 :     Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems);
44 : jhr 1978 memcpy(seq->data, elems, elemSz * nElems);
45 : jhr 1691 return seq;
46 :     }
47 :    
48 : jhr 2805 STATIC_INLINE void Diderot_DynSeqFree (Diderot_DynSeq_t *seq)
49 :     {
50 :     free (seq->data);
51 :     free (seq);
52 :     }
53 :    
54 : jhr 1733 STATIC_INLINE void *Diderot_DynSeqAddr (size_t elemSz, Diderot_DynSeq_t *seq, int i)
55 : jhr 1691 {
56 :     i = (seq->base + i) % seq->size;
57 :     return ((char *)(seq->data) + elemSz * i);
58 :     }
59 :    
60 : jhr 1714 //! append an element to a sequence
61 : jhr 1691 Diderot_DynSeq_t *Diderot_DynSeqAppend (size_t elemSz, Diderot_DynSeq_t *, void *);
62 : jhr 1714
63 :     //! prepend an element to a sequence
64 : jhr 1691 Diderot_DynSeq_t *Diderot_DynSeqPrepend (size_t elemSz, void *, Diderot_DynSeq_t *);
65 : jhr 1714
66 :     //! concatenate two sequences
67 : jhr 1691 Diderot_DynSeq_t *Diderot_DynSeqConcat (size_t elemSz, Diderot_DynSeq_t *, Diderot_DynSeq_t *);
68 :    
69 : jhr 1714 //! \brief copy the elements of a sequence to an array
70 :     //! \param elemSz the size of the sequence elements in bytes
71 :     //! \param dst the destination array
72 :     //! \param seq the source sequence
73 :     //! \return the address of the element that follows the array
74 :     void *Diderot_DynSeqCopy (size_t elemSz, void *dst, Diderot_DynSeq_t *seq);
75 :    
76 : jhr 2033
77 : jhr 1978 //! load a dynamic sequence from a Nrrd file, where the sequence elements have bool ground type.
78 :     //! \param wrld the world; used to report errors
79 :     //! \param nin the nrrd to check
80 :     //! \param nDims the number of dimensions in the sequence elements
81 :     //! \param dims the array of sequence element dimensions
82 :     //! \return the dynamic sequence, or zero on error
83 :     Diderot_DynSeq_t *Diderot_DynSeqLoadBool (WorldPrefix_t *wrld, Nrrd *nin, unsigned int nDims, unsigned int *dims);
84 :    
85 : jhr 2033 //! load a dynamic sequence from a Nrrd file, where the sequence elements have bool ground type.
86 :     //! \param wrld the world; used to report errors
87 :     //! \param name the name of the nrrd file to load
88 :     //! \param nDims the number of dimensions in the sequence elements
89 :     //! \param dims the array of sequence element dimensions
90 :     //! \return the dynamic sequence, or zero on error
91 :     Diderot_DynSeq_t *Diderot_DynSeqLoadBoolFromFile (WorldPrefix_t *wrld, const char *name, unsigned int nDims, unsigned int *dims);
92 :    
93 : jhr 1978 //! load a dynamic sequence from a Nrrd file, where the sequence elements have int ground type.
94 :     //! \param wrld the world; used to report errors
95 :     //! \param nin the nrrd to check
96 :     //! \param nDims the number of dimensions in the sequence elements
97 :     //! \param dims the array of sequence element dimensions
98 :     //! \return the dynamic sequence, or zero on error
99 :     Diderot_DynSeq_t *Diderot_DynSeqLoadInt (WorldPrefix_t *wrld, Nrrd *nin, unsigned int nDims, unsigned int *dims);
100 :    
101 : jhr 2033 //! load a dynamic sequence from a Nrrd file, where the sequence elements have int ground type.
102 :     //! \param wrld the world; used to report errors
103 :     //! \param name the name of the nrrd file to load
104 :     //! \param nDims the number of dimensions in the sequence elements
105 :     //! \param dims the array of sequence element dimensions
106 :     //! \return the dynamic sequence, or zero on error
107 :     Diderot_DynSeq_t *Diderot_DynSeqLoadIntFromFile (WorldPrefix_t *wrld, const char *name, unsigned int nDims, unsigned int *dims);
108 :    
109 : jhr 1978 //! load a dynamic sequence from a Nrrd file, where the sequence elements have real ground type.
110 :     //! \param wrld the world; used to report errors
111 :     //! \param nin the nrrd to check
112 :     //! \param nDims the number of dimensions in the sequence elements
113 :     //! \param dims the array of sequence element dimensions
114 :     //! \return the dynamic sequence, or zero on error
115 :     Diderot_DynSeq_t *Diderot_DynSeqLoadReal (WorldPrefix_t *wrld, Nrrd *nin, unsigned int nDims, unsigned int *dims);
116 :    
117 : jhr 2033 //! load a dynamic sequence from a Nrrd file, where the sequence elements have real ground type.
118 :     //! \param wrld the world; used to report errors
119 :     //! \param name the name of the nrrd file to load
120 :     //! \param nDims the number of dimensions in the sequence elements
121 :     //! \param dims the array of sequence element dimensions
122 :     //! \return the dynamic sequence, or zero on error
123 :     Diderot_DynSeq_t *Diderot_DynSeqLoadRealFromFile (WorldPrefix_t *wrld, const char *name, unsigned int nDims, unsigned int *dims);
124 :    
125 : jhr 1691 #endif /* !_DIDEROT_DYN_SEQ_H_ */

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