Newer
Older
snipet / jpcc / trunk / include / string_manager.h
#ifndef STRING_MANAGER_H
#define STRING_MANAGER_H

#include <stddef.h>
#include <stdbool.h>


#ifdef __cplusplus
extern "C" {
#endif



/**
 * 文字列を管理します.
 * create関数にて渡された文字列をコピー&管理します.
 * 管理した文字列は, clean 関数にて破棄できます.
 */
typedef struct StringManager_
{
	/**
	 * 指定された文字列を管理します.
	 * 指定された文字列は管理領域にコピーされ,
	 * 管理された文字列へのポインタを返します.
	 *
	 * @param[in,out] sm  文字列管理
	 * @param[in]     str 管理に加える文字列
	 * @return 加えられた文字列
	 */
	char*  (*create)(struct StringManager_* const sm, const char* const str);

	/**
	 * 管理している文字列をクリアします.
	 *
	 * @param[in,out] sm 文字列管理
	 */
	void   (*clean )(struct StringManager_* const sm);

	int    size;		///< 現在の使用データサイズ.
	size_t capacity;	///< 文字列管理データ容量.
	bool   isAutoExt;	///< サイズ自動拡張有効/無効.
	char*  data;		///< 文字列管理データ.
} StringManager;


StringManager* StringManager_new(const size_t cap, const bool ext);
void           StringManager_delete(StringManager* const sm);



#ifdef __cplusplus
}
#endif

#endif	/* STRING_MANAGER_H	*/