Migration Advice - AcString Type
来源:互联网 发布:名校情结 知乎 编辑:程序博客网 时间:2024/06/06 20:03
The original file is at http://private.peterlink.ru/poleshchuk/cad/2006/M2007-AcStringe.htm
A.Rivilis. Migration Advice - AcString Type
This is a continuation of the theme: migration of ARX applications to AutoCAD 2007.
In ObjectARX there is a special class (data type) AcString declared in AcString.h of versions 2006 and 2007 (in ObjectARX 2005 or earlier there is no such a type). Text string declaration when using the class looks like the following one:
AcString str;
This data type is very much alike CString type (from the MFC library) and std::string (from the standard library, STL) but is different because it allows to operate both on strings containing char symbols and on string containing wchar_t symbols. The AcString class has constructors creating strings from char type and wchar_t type, e.g.:
AcString sa("String of char");
AcString sw(_T("String of wchar_t"));
With the help of a corresponding constructor one can create an empty string or a string initialized with a symbol of type char or of type wchar_t.
AcString type assists in conversion between char and wchar_t types, e.g.:
const char *pStrA1 = sa.kszPtr();
or
const char *pStrA2 = sa; // implicitely (const char *)sa; is called
const wchar_t *pStrW1 = sa.kwszPtr();
const wchar_t *pStrW2 = sa; // implicitely (const wchar_t *)sa; is called
Moreover the class has operators/functions for string concatenation, substring search and selection, getting string length, formatting, conversion to number and so on. Using AcString type allows to write the code that in overwhelming majority of cases will work in AutoCAD 2006 as well as in AutoCAD 2007 and next versions.
As an example, the following expression will work in both versions of AutoCAD:
acedPrompt (AcString("/nПечатаем строку"));
You must be careful only while calling the function with a variable number of arguments (e.g. acutPrintf when number of arguments is greater than one, as well as acedCommand, acutBuildList) because compilator cannot understand what type is to be passed. In these cases it is more preferable to use methods AcString::kszPtr() and AcString::kwszPtr() for explicit clarification of data type. On basis of this class it is convenient to make macros for passing required type to functions, e.g.:
#ifndef INC_UNI_H
#include <AcString.h>
#define INC_UNI_H
#if defined(ACADR17)
// Conversion from UNICODE to ANSI
#define W2C(x) ((const char *)AcString(x))
// Conversion from ANSI to UNICODE
#define C2W(x) ((const wchar_t *)AcString(x))
#else
#define W2C(x) (x)
#define C2W(x) (x)
#endif
#endif
If for preprocessor in ObjectARX 2006 project the ACADR16 identifier is set or in ObjectARX 2007 project the ACADR17 identifier is set then the lines
char *str1 = "/nPrinting a string <%s>";
char *str2 = "---my string---";
acutPrintf(C2W(str1), C2W(str2));
will be compiled rightly and will work in both versions of AutoCAD.
Similarly the following expression will be compiled without errors and will be normally executed:
acedCommand (RTSTR, C2W("_.LINE"), RTSTR, C2W("0,0"), RTSTR, C2W("10,10"), RTNONE);
(Translation: N.Poleshchuk)
- Migration Advice - AcString Type
- acutPrintf AcString
- Advice
- advice
- advice
- Migration
- Migration
- Migration
- Migration
- Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
- Caused by: org.xml.sax.SAXParseException: Element type "tx:advice" must be declared.
- aop.AopInvocationException: null return value from advice does not match primitive return type for
- Bean named 'transactionAdvice' must be of type [org.aopalliance.aop.Advice], but was actually of typ
- Spring之AOP奇葩报错:Null return value from advice does not match primitive return type for
- Some advice
- Advice 通知
- Advice 通知
- express---advice
- 谁是真的英雄? csdn社区专家另类数据挖掘
- 博客搬家到CSDN
- Windows基本的数据类型
- 为什么开源产业不同于沃尔玛
- 咖啡只是一种习惯
- Migration Advice - AcString Type
- Primary Advices for Migration from ObjectARX 2004-6 to ObjectARX 2007-8
- C#精髓【月儿原创】第二讲 WMI完美秀出CPU编号厂商主频百分比等全部信息
- 职场行为准则
- 堆和栈的区别
- 《设计模式解析》摘录(9)
- ANSI与UNICODE
- Just a kidding--how to test a match
- Linux-C-Socket编程