ab.com コミュニティ

ActiveBasicを通したコミュニケーション
現在時刻 - 2024年3月28日(木) 19:21

全ての表示時間は UTC+09:00 です




新しいトピックを投稿する  トピックへ返信する  [ 1 件の記事 ] 
作成者 メッセージ
投稿記事Posted: 2005年6月11日(土) 23:43 
オフライン

登録日時: 2005年5月31日(火) 17:59
記事: 899
お住まい: 東京都
http://www.discoversoft.net/forum/viewtopic.php?t=100
ここのを読んでふと思いついた即席クラスです。
コード:
Class PSTR
Public
	Ptr As BytePtr
	Sub PSTR(p As BytePtr)
		Ptr = p
	End Sub
	
	Function MakeStr() As String
		MakeStr = MakeStr(Ptr)
	End Function
End Class

Class AutoBytePtr
	Inherits PSTR
Public
	Sub AutoBytePtr(p As BytePtr)
		PSTR(p)
	End Sub

	Sub ~AutoBytePtr()
		free(Ptr)
	End Sub
End Class

Class ByteBufStr
	Inherits AutoBytePtr
Public
	Sub ByteBufStr(pStr As BytePtr)
		AutoBytePtr(malloc(lstrlen(pStr) + 1))
		lstrcpy(Ptr, pStr)
	End Sub
End Class
PSTRは単に変数宣言と同時に文字列リテラルへのポインタで初期化できるようにしただけ。
AutoBytePtrはスマートポインタの機能を持たせた。
ByteBufStrは文字列のコピーを作ってそこへのポインタを保持させるようにした。
といった具合です。

そして例えばこんな風に使えます。
コード:
#prompt
Dim p1 As PSTR("Hello,")
Dim p2 As AutoBytePtr(malloc(4))
lstrcpy(p2.Ptr, "AB")
Dim p3 As ByteBufStr("World.")

Print p1.MakeStr(); p2.MakeStr(); p3.MakeStr()


通報する
ページトップ
期間内表示:  ソート  
新しいトピックを投稿する  トピックへ返信する  [ 1 件の記事 ] 

全ての表示時間は UTC+09:00 です


オンラインデータ

このフォーラムを閲覧中のユーザー: なし & ゲスト[8人]


トピック投稿:  可
返信投稿:  可
記事編集: 不可
記事削除: 不可
ファイル添付: 不可

検索:
ページ移動:  
cron
Powered by phpBB® Forum Software © phpBB Limited
Japanese translation principally by ocean