1 | /* $Id: strcache.h 44529 2013-02-04 15:54:15Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - String Cache, stub implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___iprt_strcache_h
|
---|
28 | #define ___iprt_strcache_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 | RT_C_DECLS_BEGIN
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Create a new string cache.
|
---|
37 | *
|
---|
38 | * @returns IPRT status code
|
---|
39 | *
|
---|
40 | * @param phStrCache Where to return the string cache handle.
|
---|
41 | * @param pszName The name of the cache (for debug purposes).
|
---|
42 | */
|
---|
43 | RTDECL(int) RTStrCacheCreate(PRTSTRCACHE phStrCache, const char *pszName);
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Destroys a string cache.
|
---|
48 | *
|
---|
49 | * This will cause all strings in the cache to be released and thus become
|
---|
50 | * invalid.
|
---|
51 | *
|
---|
52 | * @returns IPRT status.
|
---|
53 | *
|
---|
54 | * @param hStrCache Handle to the string cache. The nil and default
|
---|
55 | * handles are ignored quietly (VINF_SUCCESS).
|
---|
56 | */
|
---|
57 | RTDECL(int) RTStrCacheDestroy(RTSTRCACHE hStrCache);
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Enters a string into the cache.
|
---|
62 | *
|
---|
63 | * @returns Pointer to a read-only copy of the string.
|
---|
64 | *
|
---|
65 | * @param hStrCache Handle to the string cache.
|
---|
66 | * @param pchString Pointer to a string. This does not need to be
|
---|
67 | * zero terminated, but must not contain any zero
|
---|
68 | * characters.
|
---|
69 | * @param cchString The number of characters (bytes) to enter.
|
---|
70 | *
|
---|
71 | * @remarks It is implementation dependent whether the returned string pointer
|
---|
72 | * differs when entering the same string twice.
|
---|
73 | */
|
---|
74 | RTDECL(const char *) RTStrCacheEnterN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Enters a string into the cache.
|
---|
78 | *
|
---|
79 | * @returns Pointer to a read-only copy of the string.
|
---|
80 | *
|
---|
81 | * @param hStrCache Handle to the string cache.
|
---|
82 | * @param psz Pointer to a zero terminated string.
|
---|
83 | *
|
---|
84 | * @remarks See RTStrCacheEnterN.
|
---|
85 | */
|
---|
86 | RTDECL(const char *) RTStrCacheEnter(RTSTRCACHE hStrCache, const char *psz);
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Retains a reference to a string.
|
---|
91 | *
|
---|
92 | * @returns The new reference count. UINT32_MAX is returned if the string
|
---|
93 | * pointer is invalid.
|
---|
94 | */
|
---|
95 | RTDECL(uint32_t) RTStrCacheRetain(const char *psz);
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Releases a reference to a string.
|
---|
99 | *
|
---|
100 | * @returns The new reference count.
|
---|
101 | * UINT32_MAX is returned if the string pointer is invalid.
|
---|
102 | *
|
---|
103 | * @param hStrCache Handle to the string cache. Passing NIL is ok,
|
---|
104 | * but this may come a performance hit.
|
---|
105 | * @param psz Pointer to a cached string.
|
---|
106 | */
|
---|
107 | RTDECL(uint32_t) RTStrCacheRelease(RTSTRCACHE hStrCache, const char *psz);
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Gets the string length of a cache entry.
|
---|
111 | *
|
---|
112 | * @returns The string length. 0 if the string is invalid (asserted).
|
---|
113 | *
|
---|
114 | * @param psz Pointer to a cached string.
|
---|
115 | */
|
---|
116 | RTDECL(size_t) RTStrCacheLength(const char *psz);
|
---|
117 |
|
---|
118 | RT_C_DECLS_END
|
---|
119 |
|
---|
120 | #endif
|
---|
121 |
|
---|