Как преобразовать const char [14] в "string_t?

Рейтинг: 0Ответов: 0Опубликовано: 29.04.2023

Все здравствуйте. Есть такая функция:

AcceptInput("SetParentAttachment", Tower, Tower, variant_t(), 0);

меня интересует конкретно variant_t().

variant_t() принимает значения только, если я верно понял, string_t. Пытаюсь инициализировать:

    variant_t VariantString;    
    VariantString.SetString(ATTACHMENT_BARREL);  //ATTACHMENT_BARREL это #define(текст)

естественно получаю ошибку - IntelliSense: не существует подходящего конструктора для преобразования из "const char [14]" в "string_t" С текстовыми значениями, функциями и т.п. я очень слаб. Как можно решить эту проблему? Движек Source #define ATTACHMENT_TOWER "attach_tower" //обычный текст - char (это в шапке)

Как здесь всё неудобно устроено, форматирование кривое, напрочь.

variant_t, я так понимаю, это внутренняя функция движка, просит именно string_t, это unput данные, но не с клавы а от созданной энтити(ENT).

Файл .h

#ifndef VARIANT_T_H
#define VARIANT_T_H
#ifdef _WIN32
#pragma once
#endif


#include "ehandle.h"
#include "mathlib/vmatrix.h"

class CBaseEntity;


//
// A variant class for passing data in entity input/output connections.
//
class variant_t
{
    union
    {
        bool bVal;
        string_t iszVal;
        int iVal;
        float flVal;
        float vecVal[3];
        color32 rgbaVal;
    };
    CHandle<CBaseEntity> eVal; // this can't be in the union because it has a constructor.

    fieldtype_t fieldType;

public:

    // constructor
    variant_t() : fieldType(FIELD_VOID), iVal(0) {}

    inline bool Bool( void ) const                      { return( fieldType == FIELD_BOOLEAN ) ? bVal : false; }
    inline const char *String( void ) const             { return( fieldType == FIELD_STRING ) ? STRING(iszVal) : ToString(); }
    inline string_t StringID( void ) const              { return( fieldType == FIELD_STRING ) ? iszVal : NULL_STRING; }
    inline int Int( void ) const                        { return( fieldType == FIELD_INTEGER ) ? iVal : 0; }
    inline float Float( void ) const                    { return( fieldType == FIELD_FLOAT ) ? flVal : 0; }
    inline const CHandle<CBaseEntity> &Entity(void) const;
    inline color32 Color32(void) const                  { return rgbaVal; }
    inline void Vector3D(Vector &vec) const;

    fieldtype_t FieldType( void ) { return fieldType; }

    void SetBool( bool b ) { bVal = b; fieldType = FIELD_BOOLEAN; }
    void SetString( string_t str ) { iszVal = str, fieldType = FIELD_STRING; }
    void SetInt( int val ) { iVal = val, fieldType = FIELD_INTEGER; }
    void SetFloat( float val ) { flVal = val, fieldType = FIELD_FLOAT; }
    void SetEntity( CBaseEntity *val );
    void SetVector3D( const Vector &val ) { vecVal[0] = val[0]; vecVal[1] = val[1]; vecVal[2] = val[2]; fieldType = FIELD_VECTOR; }
    void SetPositionVector3D( const Vector &val ) { vecVal[0] = val[0]; vecVal[1] = val[1]; vecVal[2] = val[2]; fieldType = FIELD_POSITION_VECTOR; }
    void SetColor32( color32 val ) { rgbaVal = val; fieldType = FIELD_COLOR32; }
    void SetColor32( int r, int g, int b, int a ) { rgbaVal.r = r; rgbaVal.g = g; rgbaVal.b = b; rgbaVal.a = a; fieldType = FIELD_COLOR32; }
    void Set( fieldtype_t ftype, void *data );
    void SetOther( void *data );
    bool Convert( fieldtype_t newType );

    static typedescription_t m_SaveBool[];
    static typedescription_t m_SaveInt[];
    static typedescription_t m_SaveFloat[];
    static typedescription_t m_SaveEHandle[];
    static typedescription_t m_SaveString[];
    static typedescription_t m_SaveColor[];
    static typedescription_t m_SaveVector[];
    static typedescription_t m_SavePositionVector[];
    static typedescription_t m_SaveVMatrix[];
    static typedescription_t m_SaveVMatrixWorldspace[];
    static typedescription_t m_SaveMatrix3x4Worldspace[];

protected:

    //
    // Returns a string representation of the value without modifying the variant.
    //
    const char *ToString( void ) const;

    friend class CVariantSaveDataOps;
};


//-----------------------------------------------------------------------------
// Purpose: Returns this variant as a vector.
//-----------------------------------------------------------------------------
inline void variant_t::Vector3D(Vector &vec) const
{
    if (( fieldType == FIELD_VECTOR ) || ( fieldType == FIELD_POSITION_VECTOR ))
    {
        vec[0] =  vecVal[0];
        vec[1] =  vecVal[1];
        vec[2] =  vecVal[2];
    }
    else
    {
        vec = vec3_origin;
    }
}

//-----------------------------------------------------------------------------
// Purpose: Returns this variant as an EHANDLE.
//-----------------------------------------------------------------------------
inline const CHandle<CBaseEntity> &variant_t::Entity(void) const
{
    if ( fieldType == FIELD_EHANDLE )
        return eVal;

    static CHandle<CBaseEntity> hNull;
    hNull.Set(NULL);
    return(hNull);
}


#endif // VARIANT_T_H

Ответы

Ответов пока нет.