]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/src/engine/object.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / tools / build / src / engine / object.h
CommitLineData
7c673cae
FG
1/*
2 * Copyright 2011 Steven Watanabe
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7/*
8 * object.h - object manipulation routines
9 */
10
11#ifndef BOOST_JAM_OBJECT_H
12#define BOOST_JAM_OBJECT_H
13
92f5a8d4 14#include "config.h"
20effc67
TL
15#include <string>
16#include <cstring>
92f5a8d4 17
7c673cae
FG
18typedef struct _object OBJECT;
19
20OBJECT * object_new( char const * const );
21OBJECT * object_new_range( char const * const, int const size );
22void object_done( void );
23
24#if defined(NDEBUG) && !defined(BJAM_NO_MEM_CACHE)
25
26struct hash_header
27{
28 unsigned int hash;
29 struct hash_item * next;
30};
31
32#define object_str( obj ) ((char const *)(obj))
33#define object_copy( obj ) (obj)
34#define object_free( obj ) ((void)0)
35#define object_equal( lhs, rhs ) ((lhs) == (rhs))
36#define object_hash( obj ) (((struct hash_header *)((char *)(obj) - sizeof(struct hash_header)))->hash)
37
38#else
39
40char const * object_str ( OBJECT * );
41OBJECT * object_copy ( OBJECT * );
42void object_free ( OBJECT * );
43int object_equal( OBJECT *, OBJECT * );
44unsigned int object_hash ( OBJECT * );
45
46#endif
47
20effc67
TL
48namespace b2 { namespace jam {
49
50 struct object
51 {
52 inline object(const object &o)
53 : obj(object_copy(o.obj)) {}
54
55 inline explicit object(OBJECT *o)
56 : obj(object_copy(o)) {}
57 inline explicit object(const char * val)
58 : obj(object_new(val)) {}
59 inline explicit object(const std::string &val)
60 : obj(object_new(val.c_str())) {}
61
62 inline ~object() { if (obj) object_free(obj); }
63 inline OBJECT * release() { OBJECT *r = obj; obj = nullptr; return r; }
64
65 inline operator OBJECT*() const { return obj; }
66 inline operator std::string() const { return object_str(obj); }
67
68 inline bool operator==(OBJECT *o) const { return std::strcmp(object_str(obj), object_str(o)) == 0; }
69
70 private:
71
72 OBJECT * obj = nullptr;
73 };
74
75}}
76
7c673cae 77#endif