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

Reference to string objects. More...

#include <container_ext.h>

Inheritance diagram for mxnet::runtime::String:
Inheritance graph
Collaboration diagram for mxnet::runtime::String:
Collaboration graph

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...
 
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...
 
const char * data () const
 Return the data pointer. More...
 
 operator std::string () const
 Convert String to an std::string object. More...
 
 MXNET_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS (String, ObjectRef, StringObj)
 
- Public Member Functions inherited from mxnet::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
 
template<typename ObjectType >
const ObjectType * as () const
 Try to downcast the internal Object to a raw pointer of a corresponding type. More...
 

Static Public Member Functions

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

Friends

struct mxnet::runtime::ObjectRefEqual
 
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 mxnet::runtime::ObjectRef
using ContainerType = Object
 type indicate the container type. More...
 
- Static Public Attributes inherited from mxnet::runtime::ObjectRef
static constexpr bool _type_is_nullable = true
 
- Protected Member Functions inherited from mxnet::runtime::ObjectRef
Objectget_mutable () const
 
- Static Protected Member Functions inherited from mxnet::runtime::ObjectRef
template<typename T >
static T DowncastNoCheck (ObjectRef ref)
 Internal helper function downcast a ref without check. 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 mxnet::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;

Constructor & Destructor Documentation

◆ String() [1/3]

mxnet::runtime::String::String ( )
inline

Construct an empty string.

◆ String() [2/3]

mxnet::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/3]

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

Construct a new String object.

Parameters
othera char array.

Member Function Documentation

◆ c_str()

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

Returns a pointer to the char array in the string.

Returns
const char*

◆ CanConvertFrom()

bool mxnet::runtime::String::CanConvertFrom ( const MXNetArgValue val)
inlinestatic

Check if a MXNetArgValue 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 mxnet::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 mxnet::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 mxnet::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* mxnet::runtime::String::data ( ) const
inline

Return the data pointer.

Returns
const char* data pointer

◆ empty()

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

Retun if the string is empty.

Returns
true if empty, false otherwise.

◆ HashBytes()

static size_t mxnet::runtime::String::HashBytes ( const char *  data,
size_t  size 
)
inlinestatic

Hash the binary bytes.

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

◆ length()

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

Return the length of the string.

Returns
size_t string length

◆ MXNET_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS()

mxnet::runtime::String::MXNET_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS ( String  ,
ObjectRef  ,
StringObj   
)

◆ operator std::string()

mxnet::runtime::String::operator std::string ( ) const
inline

Convert String to an std::string object.

Returns
std::string

◆ operator=() [1/2]

String & mxnet::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 & mxnet::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 mxnet::runtime::String::size ( ) const
inline

Return the length of the string.

Returns
size_t string length

Friends And Related Function Documentation

◆ mxnet::runtime::ObjectRefEqual

friend struct mxnet::runtime::ObjectRefEqual
friend

◆ 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

The documentation for this class was generated from the following files:
mxnet::runtime::String::String
String()
Construct an empty string.
Definition: container_ext.h:495