Inital Commit
[oweals/finalsclub.git] / node_modules / mongodb / external-libs / bson / objectid.h
1 #ifndef OBJECTID_H_
2 #define OBJECTID_H_
3
4 #include <node.h>
5 #include <node_object_wrap.h>
6 #include <v8.h>
7
8 using namespace v8;
9 using namespace node;
10
11 class ObjectID : public ObjectWrap {  
12   public:
13     
14     static const int32_t OBJECTID_SIZE = 24+1;
15     
16     char oid[OBJECTID_SIZE];
17     
18     ObjectID(char *oid);
19     ~ObjectID();    
20
21     static inline bool HasInstance(Handle<Value> val) {
22       if (!val->IsObject()) return false;
23       Local<Object> obj = val->ToObject();
24       return constructor_template->HasInstance(obj);
25     }    
26
27     // Functions available from V8
28     static void Initialize(Handle<Object> target);    
29     static Handle<Value> ToString(const Arguments &args);
30     static Handle<Value> Inspect(const Arguments &args);
31     static Handle<Value> ToHexString(const Arguments &args);
32     static Handle<Value> ToJSON(const Arguments &args);
33     static Handle<Value> CreatePk(const Arguments &args);
34     static Handle<Value> CreateFromHexString(const Arguments &args);
35                 static Handle<Value> Equals(const Arguments &args);
36
37     // Properties
38     static Handle<Value> IdGetter(Local<String> property, const AccessorInfo& info);
39     static void IdSetter(Local<String> property, Local<Value> value, const AccessorInfo& info);
40
41     // Constructor used for creating new Long objects from C++
42     static Persistent<FunctionTemplate> constructor_template;
43     // Instance methods
44     char *convert_hex_oid_to_bin();    
45                 bool equals(ObjectID *object_id);
46   private:
47     static Handle<Value> New(const Arguments &args);
48     
49     // Generates oid's (Based on BSON C lib)
50     static char *oid_id_generator(char* buffer);
51     static char *uint32_to_char(uint32_t value, char* buffer);    
52 };
53
54 #endif  // OBJECTID_H_