tvm
Public Member Functions | Static Public Member Functions | Friends | List of all members
tvm::runtime::String Class Reference

Reference to string objects. More...

#include <string.h>

Inheritance diagram for tvm::runtime::String:
Collaboration diagram for tvm::runtime::String:

Public Member Functions

 String ()
 Construct an empty string. More...
 
 String (std::string other)
 Construct a new String object. More...
 
 String (const char *other)
 Construct a new String object. More...
 
 String (std::nullptr_t)
 Construct a new null object. More...
 
Stringoperator= (std::string other)
 Change the value the reference object points to. More...
 
Stringoperator= (const char *other)
 Change the value the reference object points to. More...
 
int compare (const String &other) const
 Compares this String object to other. More...
 
int compare (const std::string &other) const
 Compares this String object to other. More...
 
int compare (const char *other) const
 Compares this to other. More...
 
const char * c_str () const
 Returns a pointer to the char array in the string. More...
 
size_t size () const
 Return the length of the string. More...
 
size_t length () const
 Return the length of the string. More...
 
bool empty () const
 Retun if the string is empty. More...
 
char at (size_t pos) const
 Read an element. More...
 
const char * data () const
 Return the data pointer. More...
 
 TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS (String, ObjectRef, StringObj)
 
- Public Member Functions inherited from tvm::runtime::ObjectRef
 ObjectRef ()=default
 default constructor More...
 
 ObjectRef (ObjectPtr< Object > data)
 Constructor from existing object ptr. More...
 
bool same_as (const ObjectRef &other) const
 Comparator. More...
 
bool operator== (const ObjectRef &other) const
 Comparator. More...
 
bool operator!= (const ObjectRef &other) const
 Comparator. More...
 
bool operator< (const ObjectRef &other) const
 Comparator. More...
 
bool defined () const
 
const Objectget () const
 
const Objectoperator-> () const
 
bool unique () const
 
int use_count () const
 
template<typename ObjectType , typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>>
const ObjectType * as () const
 Try to downcast the internal Object to a raw pointer of a corresponding type. More...
 
template<typename ObjectRefType , typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
Optional< ObjectRefType > as () const
 Try to downcast the ObjectRef to a Optional<T> of the requested type. More...
 

Static Public Member Functions

static bool CanConvertFrom (const TVMArgValue &val)
 Check if a TVMArgValue can be converted to String, i.e. it can be std::string or String. More...
 
static uint64_t StableHashBytes (const char *data, size_t size)
 Hash the binary bytes. More...
 

Friends

struct tvm::runtime::ObjectEqual
 
String operator+ (const String &lhs, const String &rhs)
 
String operator+ (const String &lhs, const std::string &rhs)
 
String operator+ (const std::string &lhs, const String &rhs)
 
String operator+ (const String &lhs, const char *rhs)
 
String operator+ (const char *lhs, const String &rhs)
 

Additional Inherited Members

- Public Types inherited from tvm::runtime::ObjectRef
using ContainerType = Object
 type indicate the container type. More...
 
- Static Public Attributes inherited from tvm::runtime::ObjectRef
static constexpr bool _type_is_nullable = true
 
- Protected Member Functions inherited from tvm::runtime::ObjectRef
Objectget_mutable () const
 
- Static Protected Member Functions inherited from tvm::runtime::ObjectRef
template<typename T >
static T DowncastNoCheck (ObjectRef ref)
 Internal helper function downcast a ref without check. More...
 
static void FFIClearAfterMove (ObjectRef *ref)
 Clear the object ref data field without DecRef after we successfully moved the field. More...
 
template<typename ObjectType >
static ObjectPtr< ObjectType > GetDataPtr (const ObjectRef &ref)
 Internal helper function get data_ as ObjectPtr of ObjectType. More...
 
- Protected Attributes inherited from tvm::runtime::ObjectRef
ObjectPtr< Objectdata_
 Internal pointer that backs the reference. More...
 

Detailed Description

Reference to string objects.

// Example to create runtime String reference object from std::string
std::string s = "hello world";
// You can create the reference from existing std::string
String ref{std::move(s)};
// You can rebind the reference to another string.
ref = std::string{"hello world2"};
// You can use the reference as hash map key
std::unordered_map<String, int32_t> m;
m[ref] = 1;
// You can compare the reference object with other string objects
assert(ref == "hello world", true);
// You can convert the reference to std::string again
string s2 = (string)ref;
String()
Construct an empty string.
Definition: string.h:103

Constructor & Destructor Documentation

◆ String() [1/4]

tvm::runtime::String::String ( )
inline

Construct an empty string.

◆ String() [2/4]

tvm::runtime::String::String ( std::string  other)
inline

Construct a new String object.

Parameters
otherThe moved/copied std::string object
Note
If user passes const reference, it will trigger copy. If it's rvalue, it will be moved into other.

◆ String() [3/4]

tvm::runtime::String::String ( const char *  other)
inline

Construct a new String object.

Parameters
othera char array.

◆ String() [4/4]

tvm::runtime::String::String ( std::nullptr_t  )
inline

Construct a new null object.

Member Function Documentation

◆ at()

char tvm::runtime::String::at ( size_t  pos) const
inline

Read an element.

Parameters
posThe position at which to read the character.
Returns
The char at position

◆ c_str()

const char* tvm::runtime::String::c_str ( ) const
inline

Returns a pointer to the char array in the string.

Returns
const char*

◆ CanConvertFrom()

bool tvm::runtime::String::CanConvertFrom ( const TVMArgValue val)
inlinestatic

Check if a TVMArgValue can be converted to String, i.e. it can be std::string or String.

Parameters
valThe value to be checked
Returns
A boolean indicating if val can be converted to String

◆ compare() [1/3]

int tvm::runtime::String::compare ( const char *  other) const
inline

Compares this to other.

Parameters
otherThe character array to compare with.
Returns
zero if both char sequences compare equal. negative if this appear before other, positive otherwise.

◆ compare() [2/3]

int tvm::runtime::String::compare ( const std::string &  other) const
inline

Compares this String object to other.

Parameters
otherThe string to compare with.
Returns
zero if both char sequences compare equal. negative if this appear before other, positive otherwise.

◆ compare() [3/3]

int tvm::runtime::String::compare ( const String other) const
inline

Compares this String object to other.

Parameters
otherThe String to compare with.
Returns
zero if both char sequences compare equal. negative if this appear before other, positive otherwise.

◆ data()

const char* tvm::runtime::String::data ( ) const
inline

Return the data pointer.

Returns
const char* data pointer

◆ empty()

bool tvm::runtime::String::empty ( ) const
inline

Retun if the string is empty.

Returns
true if empty, false otherwise.

◆ length()

size_t tvm::runtime::String::length ( ) const
inline

Return the length of the string.

Returns
size_t string length

◆ operator=() [1/2]

String & tvm::runtime::String::operator= ( const char *  other)
inline

Change the value the reference object points to.

Parameters
otherThe value for the new String

◆ operator=() [2/2]

String & tvm::runtime::String::operator= ( std::string  other)
inline

Change the value the reference object points to.

Parameters
otherThe value for the new String

◆ size()

size_t tvm::runtime::String::size ( ) const
inline

Return the length of the string.

Returns
size_t string length

◆ StableHashBytes()

static uint64_t tvm::runtime::String::StableHashBytes ( const char *  data,
size_t  size 
)
inlinestatic

Hash the binary bytes.

Parameters
dataThe data pointer
sizeThe size of the bytes.
Returns
the hash value.

◆ TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS()

tvm::runtime::String::TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS ( String  ,
ObjectRef  ,
StringObj   
)

Friends And Related Function Documentation

◆ operator+ [1/5]

String operator+ ( const char *  lhs,
const String rhs 
)
friend

◆ operator+ [2/5]

String operator+ ( const std::string &  lhs,
const String rhs 
)
friend

◆ operator+ [3/5]

String operator+ ( const String lhs,
const char *  rhs 
)
friend

◆ operator+ [4/5]

String operator+ ( const String lhs,
const std::string &  rhs 
)
friend

◆ operator+ [5/5]

String operator+ ( const String lhs,
const String rhs 
)
friend

◆ tvm::runtime::ObjectEqual

friend struct tvm::runtime::ObjectEqual
friend

The documentation for this class was generated from the following files: