ON_String::ON_String( const unsigned char* s, int length )
{
	Create();
  if ( s && length > 0 ) {
    CopyToArray(length,s);
	}
}
Beispiel #2
0
ON_wString::ON_wString( const wchar_t* s, int length )
{
	Create();
  if ( s && length > 0 ) {
    CopyToArray( length, s );
	}
}
Beispiel #3
0
ON_wString::ON_wString( const unsigned char* s )
{
	Create();
  if ( s && s[0] ) {
    CopyToArray( (int)strlen((const char*)s), (const char*)s ); // the (int) is for 64 bit size_t conversion
  }
}
Beispiel #4
0
ON_wString::ON_wString( const wchar_t* s )
{
	Create();
  if ( s && s[0] ) {
    CopyToArray( (int)wcslen(s), s ); // the (int) is for 64 bit size_t conversion
  }
}
ON_String::ON_String( const char* s )
{
	Create();
  if ( s && s[0] ) {
    CopyToArray( (int)strlen(s), s ); // the (int) is for 64 bit size_t conversion
  }
}
ON_String::ON_String( const wchar_t* w, int w_length )
{
  // from substring
  Create();
  if ( w && w[0] ) {
    CopyToArray( w_length, w );
  }
}
Beispiel #7
0
static inline bool
Run(const char *path, Args... args)
{
  constexpr unsigned n = sizeof...(Args);
  const char *argv[1 + n + 1];
  CopyToArray(argv, path, args...);
  return Run(argv);
}
ON_String& ON_String::operator=( const wchar_t* w )
{
  // converts wide string to byt string
  int w_length = 0;
  if ( w ) while ( w[w_length] ) w_length++;
  CopyToArray( w_length, w);
	return *this;
}
Beispiel #9
0
 size_t NDMask::MaskedCount() const
 {
     auto maskMatrix = GetMatrix();
     std::unique_ptr<char[]> maskData(maskMatrix->CopyToArray());
     return std::count_if(maskData.get(), maskData.get() + maskMatrix->GetNumElements(), [](const char& val) {
         return val == 0;
     });
 }
Beispiel #10
0
void ON_String::CopyArray()
{
  // If 2 or more strings are using the array, it is duplicated.
  // Call CopyArray() before modifying array contents.
  ON_aStringHeader* p = Header();
  if ( p != pEmptyStringHeader && p && p->ref_count > 1 ) {
    const char* s = m_s;
    Destroy();
    CopyToArray( p->string_capacity, s );
  }
}
Beispiel #11
0
void ON_String::CopyToArray( int w_count, const wchar_t* w )
{
  // convert UTF-16 string to UTF-8 string
  int c_count = w2c_size( w_count, w );
  char* c = (char*)onmalloc(c_count+1);
  memset( c, 0, c_count+1 );
  const int c_length = w2c( w_count, w, c_count, c );
  c[c_length] = 0;
  CopyToArray( c_count, c );
  onfree(c);
}
bool ON_String::LoadResourceString( HINSTANCE instance, UINT id )
{
  char s[2048]; // room for 2047 characters
  int length;

  Destroy();
  length = ::LoadStringA( instance, id, s, 2047 );
  if ( length > 0 && length < 2048 ) {
    CopyToArray( length, s );
  }
  return (length > 0 );
}
Beispiel #13
0
ON_wString::ON_wString( unsigned char c, int repeat_count )
{
  Create();
  if ( repeat_count > 0 ) {
    char* s = (char*)onmalloc((repeat_count+1)*sizeof(*s));
    s[repeat_count] = 0;
    memset( s, c, repeat_count*sizeof(*s) );
    CopyToArray( repeat_count, s );
    onfree(s);
    m_s[repeat_count] = 0;
    Header()->string_length = repeat_count;
  }
}
Beispiel #14
0
bool ON_wString::LoadResourceString(HINSTANCE instance, UINT id )
{
  bool rc = false;
  wchar_t s[2048]; // room for 2047 characters
  int length;

  Destroy();
  length = ::LoadStringW( instance, id, s, 2047 );
  if ( length > 0 && length < 2048 ) {
    CopyToArray( length, s );
    rc = true;
  }
  return rc;
}
void ON_String::CopyArray()
{
  // If 2 or more strings are using the array, it is duplicated.
  // Call CopyArray() before modifying array contents.
  ON_aStringHeader* p = Header();
  if ( p != pEmptyStringHeader && p && p->ref_count > 1 ) 
  {
    const char* s = m_s;
    // p and s remain valid after Destroy() because
    // will simply be decremented and no deallocation
    // will happen.
    Destroy();
    CopyToArray( p->string_capacity, s );
    if ( p->string_length < p->string_capacity )
    {
      Header()->string_length = p->string_length;
    }
  }
}
void ON_MSC_CDECL ON_String::Format( const unsigned char* sFormat, ...)
{
#define MAX_MSG_LENGTH 2048
  char sMessage[MAX_MSG_LENGTH];
  va_list args;

  /* put formatted message in sMessage */
  memset(sMessage,0,sizeof(sMessage));
  if (sFormat) {
    va_start(args, sFormat);
    on_vsnprintf(sMessage, MAX_MSG_LENGTH-1, (const char*)sFormat, args);
    sMessage[MAX_MSG_LENGTH-1] = 0;
    va_end(args);
  }
  const int len = Length(sMessage);
  if ( len < 1 ) {
    Destroy();
    Create();
  }
  else {
    ReserveArray( len );
    CopyToArray( len, sMessage );
  }
}
Beispiel #17
0
/**
  Function to convert CMPIValue to CIMValue
*/
CIMValue value2CIMValue(const CMPIValue* data, const CMPIType type, CMPIrc *rc)
{
    CIMValue v;
    if( rc )
    {
        *rc=CMPI_RC_OK;
    }

/**
   check data for NULL if type is not CMPIArray.
*/
    if( !(type & CMPI_ARRAY) && !data )
    {
        return CIMValue(type2CIMType(type), false);
    }
    /**
       Case when type is CMPIArray
   */
    if( type & CMPI_ARRAY )
    {
        //Return if data itself is NULL or Array is NULL
        if( data == NULL || data->array == NULL )
        {
            CMPIType aType=type&~CMPI_ARRAY;
            return CIMValue(type2CIMType(aType),true);
        }
        // When data is not NULL and data->array is also set
        CMPIArray *ar=data->array;
        CMPIData *aData=(CMPIData*)((CMPI_Array*)ar->hdl)->hdl;

        //Get the type of the elements in the array
        CMPIType aType=aData->type&~CMPI_ARRAY;

        int aSize=aData->value.sint32;
        aData++;

        // Checks for Signed Integers
        if( (aType & (CMPI_UINT|CMPI_SINT))==CMPI_SINT )
        {
            switch( aType )
            {
                case CMPI_sint32:
                    CopyToArray(Sint32,sint32);
                    break;

                case CMPI_sint16:
                    CopyToArray(Sint16,sint16);
                    break;

                case CMPI_sint8:
                    CopyToArray(Sint8,sint8);
                    break;

                case CMPI_sint64:
                    CopyToArray(Sint64,sint64);
                    break;

                default: ;
            }
        }
        else
        if( aType == CMPI_chars )
        {
            CopyToStringArray(String,string->hdl)
        }
        else
        if( aType == CMPI_charsptr )
        {
            CopyCharsptrToStringArray(String,chars)
        }
        else
        if( aType == CMPI_string )
        {
            CopyToStringArray(String,string->hdl)
        }


        // Checks for Unsigned Integers
        else
        if( (aType & (CMPI_UINT|CMPI_SINT))==CMPI_UINT )
        {
            switch( aType )
            {
                case CMPI_uint32:
                    CopyToArray(Uint32,uint32);
                    break;
                case CMPI_uint16:
                    CopyToArray(Uint16,uint16);
                    break;
                case CMPI_uint8:
                    CopyToArray(Uint8,uint8);
                    break;
                case CMPI_uint64:
                    CopyToArray(Uint64,uint64);
                    break;
                default: ;
            }


        }
        else
        {
            switch( aType )
            {
                case CMPI_ref:
                    {
                        Array<CIMObjectPath> arCIMObjectPath(aSize);
                        ArrayIterator<CIMObjectPath> iterator(arCIMObjectPath);
                        for (int i=0; i<aSize; i++)
                        {
                            SCMOInstance* scmoInst =
                                (SCMOInstance*)aData[i].value.ref->hdl;
                            scmoInst->getCIMObjectPath(iterator[i]);
                        }
                        v.set(arCIMObjectPath);
                    }
                    break;

                case CMPI_dateTime:
                    CopyToEncArray(CIMDateTime,dateTime);
                    break;
                case CMPI_instance:
                    {
                        Array<CIMObject> arCIMInstance(aSize);
                        ArrayIterator<CIMObject> iterator(arCIMInstance);
                        for (int i=0; i<aSize; i++)
                        {
                            SCMOInstance* scmoInst =
                                (SCMOInstance*)aData[i].value.inst->hdl;
                            CIMInstance inst;
                            scmoInst->getCIMInstance(inst);
                            CIMObject obj(inst);
                            iterator[i]=obj;
                        }
                        v.set(arCIMInstance);
                    }
                    break;
                case CMPI_boolean:
                    CopyToArray(Boolean,boolean);
                    break;

                case CMPI_char16:
                    CopyToArray(Char16,char16);
                    break;

                case CMPI_real32:
                    CopyToArray(Real32,real32);
                    break;

                case CMPI_real64:
                    CopyToArray(Real64,real64);
                    break;

                default:
                    if( rc )
                    {
                        *rc=CMPI_RC_ERR_NOT_SUPPORTED;
                    }
            }
        }
        return CIMValue(v);
    } // end of array processing
    //Start of non - array types processing
    else
    if( type == CMPI_chars )
Beispiel #18
0
const ON_wString& ON_wString::operator=( wchar_t c )
{
	CopyToArray( 1, &c );
	return *this;
}
Beispiel #19
0
const ON_wString& ON_wString::operator=( const wchar_t* s )
{
  if ( (void*)s != (void*)m_s )
	  CopyToArray( Length(s), s);
	return *this;
}
ON_String& ON_String::operator=( const unsigned char* s )
{
  if ( (void*)s != (void*)m_s )
	  CopyToArray( Length(s), s);
	return *this;
}
ON_String& ON_String::operator=( unsigned char c )
{
	CopyToArray( 1, &c );
	return *this;
}
Beispiel #22
0
static inline void
CopyToArray(const char **dest, const char *src, Args... args)
{
  *dest++ = src;
  CopyToArray(dest, args...);
}
void ON_String::CopyToArray( const ON_String& s )
{
  CopyToArray( s.Length(), s.Array() );
}
void ON_String::CopyToArray( int size, const unsigned char* s )
{
  CopyToArray( size, ((char*)s) );
}