]> gitweb.factorcode.org Git - factor.git/blob - extra/bson/constants/constants.factor
Merge branch 'master' of http://github.com/Blei/factor
[factor.git] / extra / bson / constants / constants.factor
1 ! Copyright (C) 2010 Sascha Matzke.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs calendar combinators
4 combinators.short-circuit constructors kernel linked-assocs
5 math math.bitwise random strings uuid ;
6 IN: bson.constants
7
8 : <objid> ( -- objid )
9    uuid1 ; inline
10
11 TUPLE: oid { a initial: 0 } { b initial: 0 } ;
12
13 : <oid> ( -- oid )
14     oid new
15     now timestamp>micros >>a
16     8 random-bits 16 shift HEX: FF0000 mask
17     16 random-bits HEX: FFFF mask
18     bitor >>b ;
19
20 TUPLE: dbref ref id db ;
21
22 CONSTRUCTOR: dbref ( ref id -- dbref ) ;
23
24 : dbref>assoc ( dbref -- assoc )
25     [ <linked-hash> ] dip over
26     {
27         [ [ ref>> "$ref" ] [ set-at ] bi* ]
28         [ [ id>> "$id" ] [ set-at ] bi* ]
29         [ over db>> [
30                 [ db>> "$db" ] [ set-at ] bi*
31             ] [ 2drop ] if ]
32     } 2cleave ; inline
33
34 : assoc>dbref ( assoc -- dbref )
35     [ "$ref" swap at ] [ "$id" swap at ] [ "$db" swap at ] tri
36     dbref boa ; inline
37
38 : dbref-assoc? ( assoc -- ? )
39     { [ "$ref" swap key? ] [ "$id" swap key? ] } 1&& ; inline
40
41 TUPLE: mdbregexp { regexp string } { options string } ;
42
43 : <mdbregexp> ( string -- mdbregexp )
44    [ mdbregexp new ] dip >>regexp ;
45
46
47 CONSTANT: MDB_OID_FIELD "_id"
48 CONSTANT: MDB_META_FIELD "_mfd"
49
50 CONSTANT: T_EOO  0  
51 CONSTANT: T_Double  1  
52 CONSTANT: T_Integer  16  
53 CONSTANT: T_Boolean  8  
54 CONSTANT: T_String  2  
55 CONSTANT: T_Object  3  
56 CONSTANT: T_Array  4  
57 CONSTANT: T_Binary  5  
58 CONSTANT: T_Undefined  6  
59 CONSTANT: T_OID  7  
60 CONSTANT: T_Date  9  
61 CONSTANT: T_NULL  10  
62 CONSTANT: T_Regexp  11  
63 CONSTANT: T_DBRef  12  
64 CONSTANT: T_Code  13  
65 CONSTANT: T_ScopedCode  17  
66 CONSTANT: T_Symbol  14  
67 CONSTANT: T_JSTypeMax  16  
68 CONSTANT: T_MaxKey  127  
69
70 CONSTANT: T_Binary_Function 1   
71 CONSTANT: T_Binary_Bytes 2
72 CONSTANT: T_Binary_UUID 3
73 CONSTANT: T_Binary_MD5 5
74 CONSTANT: T_Binary_Custom 128
75
76