greenplumn CWStringBase 源码

  • 2022-08-18
  • 浏览 (331)

greenplumn CWStringBase 代码

文件路径:/src/backend/gporca/libgpos/include/gpos/string/CWStringBase.h

//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2010 Greenplum, Inc.
//
//	@filename:
//		CWStringBase.h
//
//	@doc:
//		Abstract wide character string class
//---------------------------------------------------------------------------
#ifndef GPOS_CWStringBase_H
#define GPOS_CWStringBase_H

#include "gpos/common/clibwrapper.h"
#include "gpos/types.h"

#define GPOS_WSZ_LENGTH(x) gpos::clib::Wcslen(x)
#define GPOS_WSZ_STR_LENGTH(x) GPOS_WSZ_LIT(x), GPOS_WSZ_LENGTH(GPOS_WSZ_LIT(x))

#define WCHAR_EOS GPOS_WSZ_LIT('\0')


namespace gpos
{
class CWStringConst;
class CMemoryPool;

//---------------------------------------------------------------------------
//	@class:
//		CWStringBase
//
//	@doc:
//		Abstract wide character string class.
//		Currently, the class has two derived classes: CWStringConst and CWString.
//		CWString is used to represent constant strings that once initialized are never
//		modified. This class is not responsible for any memory management, rather
//		its users are in charge for allocating and releasing the necessary memory.
//		In contrast, CWString can be used to store strings that are modified after
//		they are created. CWString is in charge of dynamically allocating and deallocating
//		memory for storing the characters of the string.
//
//---------------------------------------------------------------------------
class CWStringBase
{
private:
protected:
	// represents end-of-wide-string character
	static const WCHAR m_empty_wcstr;

	// size of the string in number of WCHAR units (not counting the terminating '\0')
	ULONG m_length;

	// whether string owns its memory and should take care of deallocating it at destruction time
	BOOL m_owns_memory;

	// checks whether the string is byte-wise equal to a given string literal
	virtual BOOL Equals(const WCHAR *w_str_buffer) const;

public:
	CWStringBase(const CWStringBase &) = delete;

	// ctor
	CWStringBase(ULONG length, BOOL owns_memory)
		: m_length(length), m_owns_memory(owns_memory)
	{
	}

	// dtor
	virtual ~CWStringBase() = default;

	// deep copy of the string
	virtual CWStringConst *Copy(CMemoryPool *mp) const;

	// accessors
	virtual ULONG Length() const;

	// checks whether the string is byte-wise equal to another string
	virtual BOOL Equals(const CWStringBase *str) const;

	// checks whether the string contains any characters
	virtual BOOL IsEmpty() const;

	// checks whether a string is properly null-terminated
	bool IsValid() const;

	// equality operator
	BOOL operator==(const CWStringBase &str) const;

	// returns the wide character buffer storing the string
	virtual const WCHAR *GetBuffer() const = 0;

	// returns the index of the first occurrence of a character, -1 if not found
	INT Find(WCHAR wc) const;

	// checks if a character is escaped
	BOOL HasEscapedCharAt(ULONG offset) const;

	// count how many times the character appears in string
	ULONG CountOccurrencesOf(const WCHAR wc) const;
};

}  // namespace gpos

#endif	// !GPOS_CWStringBase_H

// EOF

相关信息

greenplumn 源码目录

相关文章

greenplumn CStringStatic 源码

greenplumn CWString 源码

greenplumn CWStringConst 源码

greenplumn CWStringDynamic 源码

greenplumn CWStringStatic 源码

0  赞