ctype

Beginner: Fastest way to cast/copy byte() into single()

I've got a byte() array returned as result of directx sound capture, but for other parts of my program I want to treat the results as single(). Is trundling down the array item by item the fastest way of doing it or is there a clever way to do it ? The code that gets it is CType(Me._applicationBuffer.Read(Me._nextCaptureOffset, GetTyp...

Casting in VB.Net

I would like to be able to cast a value dynamically where the type is known only on runtime. something like this myvalue = ctype (value, "String, Integer or Boolean") the string that contains the type value is passed as argument and also read from DB. And the value is stored as string in the DB. Is this possible ? Thanks in advance...

charlower with gcc

I am trying to convert the following code from msvc to gcc #define ltolower(ch) CharLower((LPSTR)(UCHAR)(ch)) char * aStr; * aStr = (char)ltolower(*aStr); This code is giving a compiler error: cast from ‘CHAR*’ to ‘char’ loses precision My understanding is that tolower(int) from c wouldn't convert the whole string. Thanks...

C++ ctype facet for UTF-8 in mingw

In a project all internal strings are kept in utf-8 encoding. The project is ported to Linux and Windows. There is a need for a to_lower functionality now. On POSIX OS I could use std::ctype_byname("ru_RU.UTF-8"). But with g++ (Debian 4.3.4-1), ctype::tolower() don't recognize Russian UTF-8 characters (latin text is lowercased fine). O...

Directcast & Ctype differences with enums

Public Enum Fruit Red_Apple = 1 Oranges Ripe_Banana End Enum Private Sub InitCombosRegular() Dim d1 As New Dictionary(Of Int16, String) For Each e In [Enum].GetValues(GetType(Fruit)) d1.Add(CShort(e), Replace(e.ToString, "_", " ")) Next ComboBox1.DataSource = d1.ToList ComboBox1.DisplayMember = "V...

C#'s equivalent to VB.Net's DirectCast?

This has probably been asked before, but if it has, I can't find it. Does C# have an equivalent to VB.Net's DirectCast? I am aware that it has () casts and the 'as' keyword, but those line up to CType and TryCast. To be clear, these keywords do the following; CType/() casts: If it is already the correct type, cast it, otherwise look f...

Casting DataTypes with DirectCast, CType, TryCast

Ever since I moved from VB6 to VB.NET somewhere in 2005, I've been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them. I use TryCast once in a while because I und...

ctypes and PySide

I'm building an app with PySide, there's some image manipulation that needs to be done and using Python code for this is way too slow. Therefore I hacked out a .dll file that will do it for me. The function definition is as follows: extern "C" { QRectF get_image_slant(QImage *img, float slantangle, float offset) { Now I can load th...

Difference between DirectCast() and CType() in VB.Net

I am an experienced C/C++/C# programmer who has just gotten into VB.NET. I generally use CType (and CInt, CBool, CStr) for casts because it is less characters and was the first way of casting which I was exposed to, but I am aware of DirectCast and TryCast as well. Simply, are there any differences (effect of cast, performance, etc.)...

Dealing with ctype.h integer overflow

What is the proper way to deal with character values which when casted to an unsigned char fall between {INT_MAX + 1 ... UCHAR_MAX} where UCHAR_MAX is greater than INT_MAX. int is_digit(char c) { unsigned char uchar = c; if(uchar > INT_MAX) return MAYBE; return isdigit((int)uchar) ? YES : NO; } ...

ctype and strings and containers

Is there any reason that the ctype facet functions (is,scan_is,scan_not only support plain char pointer, and not iterator based containers, like std::string or even a std::vector... then one could write: const ctype<char>& myctype = use_facet<std::ctype<char> >(locale("")); string foo_str = "hi there here is a number: 748574 and text ag...

Import an array of floats into Python and unpack the floats

Hello. Upfront, I do not have much programming experience. If you reply, please include detailed code comments. I need to import into Python a 512 packed floats array described by the programmer as... I pack the profile data into an array of floats (32 bit) which I store in the tag. You would see this as an array of 4*512 = 204...

How can I use Python Ctypes to override global WEAKREF function in a shared library library?

I understand I can set a global function pointer inside a sharef library to point to a python function as follows. from ctypes import * liblibrary = cdll.LoadLibrary('liblibrary.so') def py_library_hook(strings, n): return 0 # First argument to CFUNCTYPE is the return type: LIBRARY_HOOK_FUNC = CFUNCTYPE(c_int, POINTER(c_char_p), ...