github.com/256dpi/max-go@v0.7.0/lib/max/ext_obstring.h (about)

     1  /*
     2   *  obstring.h
     3   *
     4   *  Copyright 2006 Cycling '74. All rights reserved.
     5   *
     6   */
     7  
     8  #ifndef _EXT_OBSTRING_H_
     9  #define _EXT_OBSTRING_H_
    10  
    11  #include "ext_prefix.h"
    12  #include "ext_mess.h"
    13  
    14  BEGIN_USING_C_LINKAGE
    15  
    16  #if C74_PRAGMA_STRUCT_PACKPUSH
    17      #pragma pack(push, 2)
    18  #elif C74_PRAGMA_STRUCT_PACK
    19      #pragma pack(2)
    20  #endif
    21  
    22  
    23  /** 
    24  	The string object. This struct is provided for debugging convenience, 
    25  	but should be considered opaque and is subject to change without notice. 
    26  
    27  	@ingroup string
    28  */
    29  typedef struct _string
    30  {
    31  	t_object		s_obj;
    32  	char			*s_text;
    33  	long			s_size;		// number of bytes allocated
    34  } t_string;  
    35  
    36  #if C74_PRAGMA_STRUCT_PACKPUSH
    37      #pragma pack(pop)
    38  #elif C74_PRAGMA_STRUCT_PACK
    39      #pragma pack()
    40  #endif
    41  
    42  
    43  /**
    44  	Create a new string object.
    45  	@ingroup string
    46  	@param	psz		Pointer to a C-string that will be copied to memory internal to this string object instance.
    47  	@return			The new string object instance pointer.
    48  */
    49  t_string* string_new(const char *psz);
    50  
    51  
    52  /**
    53  	Fetch a pointer to a string object's internal C-string.
    54  	@ingroup string
    55  	@param	x		The string object instance.
    56  	@return			A pointer to the internally maintained C-string.
    57  */
    58  const char* string_getptr(t_string *x);
    59  
    60  		
    61  /**
    62  	Reserve additional memory for future string growth.
    63  	@ingroup string
    64  	@param	x			The string object instance.
    65  	@param	numbytes	The total number of bytes to allocate for this string object.
    66   */
    67  void string_reserve(t_string *x, long numbytes);
    68  
    69  
    70  /**
    71  	Append a C-string onto the existing string maintained by a #t_string object.
    72  	Memory allocation for the string will grow as needed to hold the concatenated string.
    73   
    74  	@ingroup string
    75  	@param	x			The string object instance.
    76  	@param	s			A string to append/concatenate with the existing string.
    77   */
    78  void string_append(t_string *x, const char *s);
    79  
    80  		
    81  /**
    82  	Shorten a string by eliminating N characters from the end.
    83   
    84  	@ingroup string
    85  	@param	x			The string object instance.
    86  	@param	numchars	The number of characters to chop from the end of the string.
    87   */
    88  void string_chop(t_string *x, long numchars);
    89  
    90  
    91  // TODO: This object has a number of additional methods exposed via Max's messaging interface
    92  
    93  END_USING_C_LINKAGE
    94  
    95  #endif //#ifndef _EXT_OBSTRING_H_