ofdbus/dbus/dbus/dbus-string-private.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /* -*- mode: C; c-file-style: "gnu" -*- */
       
     2 /* dbus-string-private.h String utility class (internal to D-Bus implementation)
       
     3  * 
       
     4  * Copyright (C) 2002, 2003  Red Hat, Inc.
       
     5  * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
     6  * Licensed under the Academic Free License version 2.1
       
     7  * 
       
     8  * This program is free software; you can redistribute it and/or modify
       
     9  * it under the terms of the GNU General Public License as published by
       
    10  * the Free Software Foundation; either version 2 of the License, or
       
    11  * (at your option) any later version.
       
    12  *
       
    13  * This program is distributed in the hope that it will be useful,
       
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  * GNU General Public License for more details.
       
    17  * 
       
    18  * You should have received a copy of the GNU General Public License
       
    19  * along with this program; if not, write to the Free Software
       
    20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef DBUS_STRING_PRIVATE_H
       
    25 #define DBUS_STRING_PRIVATE_H
       
    26 #ifndef __SYMBIAN32__
       
    27 #include <config.h>
       
    28 #else
       
    29 #include "config.h"
       
    30 #endif
       
    31 
       
    32 #include <dbus/dbus-memory.h>
       
    33 #include <dbus/dbus-types.h>
       
    34 
       
    35 #ifndef DBUS_CAN_USE_DBUS_STRING_PRIVATE
       
    36 #error "Don't go including dbus-string-private.h for no good reason"
       
    37 #endif
       
    38 
       
    39 DBUS_BEGIN_DECLS
       
    40 
       
    41 /**
       
    42  * @brief Internals of DBusString.
       
    43  * 
       
    44  * DBusString internals. DBusString is an opaque objects, it must be
       
    45  * used via accessor functions.
       
    46  */
       
    47 typedef struct
       
    48 {
       
    49   unsigned char *str;            /**< String data, plus nul termination */
       
    50   int            len;            /**< Length without nul */
       
    51   int            allocated;      /**< Allocated size of data */
       
    52   int            max_length;     /**< Max length of this string, without nul byte */
       
    53   unsigned int   constant : 1;   /**< String data is not owned by DBusString */
       
    54   unsigned int   locked : 1;     /**< DBusString has been locked and can't be changed */
       
    55   unsigned int   invalid : 1;    /**< DBusString is invalid (e.g. already freed) */
       
    56   unsigned int   align_offset : 3; /**< str - align_offset is the actual malloc block */
       
    57 } DBusRealString;
       
    58 
       
    59 
       
    60 /**
       
    61  * @defgroup DBusStringInternals DBusString implementation details
       
    62  * @ingroup  DBusInternals
       
    63  * @brief DBusString implementation details
       
    64  *
       
    65  * The guts of DBusString.
       
    66  *
       
    67  * @{
       
    68  */
       
    69 
       
    70 /**
       
    71  * This is the maximum max length (and thus also the maximum length)
       
    72  * of a DBusString
       
    73  */
       
    74 #define _DBUS_STRING_MAX_MAX_LENGTH (_DBUS_INT32_MAX - _DBUS_STRING_ALLOCATION_PADDING)
       
    75 
       
    76 /**
       
    77  * Checks a bunch of assertions about a string object
       
    78  *
       
    79  * @param real the DBusRealString
       
    80  */
       
    81 #define DBUS_GENERIC_STRING_PREAMBLE(real) _dbus_assert ((real) != NULL); _dbus_assert (!(real)->invalid); _dbus_assert ((real)->len >= 0); _dbus_assert ((real)->allocated >= 0); _dbus_assert ((real)->max_length >= 0); _dbus_assert ((real)->len <= ((real)->allocated - _DBUS_STRING_ALLOCATION_PADDING)); _dbus_assert ((real)->len <= (real)->max_length)
       
    82 
       
    83 /**
       
    84  * Checks assertions about a string object that needs to be
       
    85  * modifiable - may not be locked or const. Also declares
       
    86  * the "real" variable pointing to DBusRealString. 
       
    87  * @param str the string
       
    88  */
       
    89 #define DBUS_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
       
    90   DBUS_GENERIC_STRING_PREAMBLE (real);                                          \
       
    91   _dbus_assert (!(real)->constant);                                             \
       
    92   _dbus_assert (!(real)->locked)
       
    93 
       
    94 /**
       
    95  * Checks assertions about a string object that may be locked but
       
    96  * can't be const. i.e. a string object that we can free.  Also
       
    97  * declares the "real" variable pointing to DBusRealString.
       
    98  *
       
    99  * @param str the string
       
   100  */
       
   101 #define DBUS_LOCKED_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
       
   102   DBUS_GENERIC_STRING_PREAMBLE (real);                                                 \
       
   103   _dbus_assert (!(real)->constant)
       
   104 
       
   105 /**
       
   106  * Checks assertions about a string that may be const or locked.  Also
       
   107  * declares the "real" variable pointing to DBusRealString.
       
   108  * @param str the string.
       
   109  */
       
   110 #define DBUS_CONST_STRING_PREAMBLE(str) const DBusRealString *real = (DBusRealString*) str; \
       
   111   DBUS_GENERIC_STRING_PREAMBLE (real)
       
   112 
       
   113 /**
       
   114  * Checks for ASCII blank byte
       
   115  * @param c the byte
       
   116  */
       
   117 #define DBUS_IS_ASCII_BLANK(c) ((c) == ' ' || (c) == '\t')
       
   118 
       
   119 /**
       
   120  * Checks for ASCII whitespace byte
       
   121  * @param c the byte
       
   122  */
       
   123 #define DBUS_IS_ASCII_WHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')
       
   124 
       
   125 /** @} */
       
   126 
       
   127 DBUS_END_DECLS
       
   128 
       
   129 #endif /* DBUS_STRING_PRIVATE_H */