- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
http://www.private.peterlink.ru/ ... M2007-AcStringe.htm
ObjectARX 2007 以上加入的类,Autocad 下用这个类处理字符串足矣!
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("\nPrinting a string"));
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);
|
|