📄 creating_a_specific_attribute_class.htm
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Creating a Specific Attribute Class,Attributes" /> <link rel="shortcut icon" href="/favicon.ico" /> <link rel="search" type="application/opensearchdescription+xml" href="/r18/opensearch_desc.php" title="DocR18 (English)" /> <link title="Creative Commons" type="application/rdf+xml" href="/r18/index.php?title=Creating_a_Specific_Attribute_Class&action=creativecommons" rel="meta" /> <title>Creating a Specific Attribute Class - DocR18</title>
<style type="text/css" media="screen, projection">/*<![CDATA[*/
@import "/r18/skins/common/shared.css?97";
@import "/r18/skins/monobook/main.css?97";
/*]]>*/</style>
<link rel="stylesheet" type="text/css" media="print" href="/r18/skins/common/commonPrint.css?97" />
<!--[if lt IE 5.5000]><style type="text/css">@import "/r18/skins/monobook/IE50Fixes.css?97";</style><![endif]-->
<!--[if IE 5.5000]><style type="text/css">@import "/r18/skins/monobook/IE55Fixes.css?97";</style><![endif]-->
<!--[if IE 6]><style type="text/css">@import "/r18/skins/monobook/IE60Fixes.css?97";</style><![endif]-->
<!--[if IE 7]><style type="text/css">@import "/r18/skins/monobook/IE70Fixes.css?97";</style><![endif]-->
<!--[if lt IE 7]><script type="text/javascript" src="/r18/skins/common/IEFixes.js?97"></script>
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<script type= "text/javascript">/*<![CDATA[*/var skin = "monobook";var stylepath = "/r18/skins";var wgArticlePath = "/r18/index.php/$1";var wgScriptPath = "/r18";var wgScript = "/r18/index.php";var wgServer = "http://doc.spatial.com";var wgCanonicalNamespace = "";var wgCanonicalSpecialPageName = false;var wgNamespaceNumber = 0;var wgPageName = "Creating_a_Specific_Attribute_Class";var wgTitle = "Creating a Specific Attribute Class";var wgAction = "view";var wgRestrictionEdit = ["sysop"];var wgRestrictionMove = ["sysop"];var wgArticleId = "443";var wgIsArticle = true;var wgUserName = null;var wgUserGroups = null;var wgUserLanguage = "en";var wgContentLanguage = "en";var wgBreakFrames = false;var wgCurRevisionId = "1109";/*]]>*/</script>
<script type="text/javascript" src="/r18/skins/common/wikibits.js?97"><!-- wikibits js --></script>
<script type="text/javascript" src="/r18/index.php?title=-&action=raw&gen=js&useskin=monobook"><!-- site js --></script>
<style type="text/css">/*<![CDATA[*/@import "/r18/index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";@import "/r18/index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";@import "/r18/index.php?title=-&action=raw&gen=css&maxage=18000";/*]]>*/</style>
<!-- Head Scripts -->
<script type="text/javascript" src="/r18/skins/common/ajax.js?97"></script><style type="text/css">/*<![CDATA[*/.source-cpp {line-height: normal;}.source-cpp li {line-height: normal;}/** * GeSHi Dynamically Generated Stylesheet * -------------------------------------- * Dynamically generated stylesheet for cpp * CSS class: source-cpp, CSS id: * GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter) */.source-cpp .de1, .source-cpp .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}.source-cpp {}.source-cpp .head {}.source-cpp .foot {}.source-cpp .imp {font-weight: bold; color: red;}.source-cpp .ln-xtra {color: #cc0; background-color: #ffc;}.source-cpp li {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}.source-cpp li.li2 {font-weight: bold;}.source-cpp .kw1 {color: #0000ff;}.source-cpp .kw2 {color: #0000ff;}.source-cpp .kw3 {color: #0000dd;}.source-cpp .kw4 {color: #0000ff;}.source-cpp .kw5 {color: #000099;}.source-cpp .kw6 {color: #000099; font-weight:normal}.source-cpp .kw7 {color: #004D99;}.source-cpp .co1 {color: #006600; font-style: italic;}.source-cpp .co2 {color: #006600;}.source-cpp .coMULTI {color: #006600; font-style: italic;}.source-cpp .es0 {color: #666666; font-weight: bold;}.source-cpp .br0 {color: #B300D6;}.source-cpp .st0 {color: #999933;}.source-cpp .nu0 {color: #A30000;}.source-cpp .me1 {color: #993300;}.source-cpp .me2 {color: #993300;}@import "/r18/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";/*]]>*/</style> </head>
<body class="mediawiki ns-0 ltr page-Creating_a_Specific_Attribute_Class">
<div id="globalWrapper">
<div id="column-content">
<div id="content">
<a name="top" id="top"></a>
<h1 class="firstHeading">Creating a Specific Attribute Class</h1>
<div id="bodyContent">
<h3 id="siteSub">From DocR18</h3>
<div id="contentSub"></div>
<div id="jump-to-nav">Jump to: <a href="#column-one">navigation</a>, <a href="#searchInput">search</a></div> <!-- start content -->
<p>After the organization attribute class (which cannot be instantiated) has been defined, specific attribute classes (which can be instantiated) may be derived from it.</p><table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Contents</h2></div><ul><li class="toclevel-1"><a href="#Derived_Simple_Attribute"><span class="tocnumber">1</span> <span class="toctext">Derived Simple Attribute</span></a><ul><li class="toclevel-2"><a href="#Color_Attribute_Header_File"><span class="tocnumber">1.1</span> <span class="toctext">Color Attribute Header File</span></a><ul><li class="toclevel-3"><a href="#C.2B.2B_Example"><span class="tocnumber">1.1.1</span> <span class="toctext">C++ Example</span></a></li></ul></li><li class="toclevel-2"><a href="#Color_Attribute_Implementation_File"><span class="tocnumber">1.2</span> <span class="toctext">Color Attribute Implementation File</span></a><ul><li class="toclevel-3"><a href="#C.2B.2B_Example_2"><span class="tocnumber">1.2.1</span> <span class="toctext">C++ Example</span></a></li></ul></li><li class="toclevel-2"><a href="#Complex_Attribute_Boolean_Conditions"><span class="tocnumber">1.3</span> <span class="toctext">Complex Attribute Boolean Conditions</span></a></li></ul></li></ul></li></ul></td></tr></table><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script><a name="Derived_Simple_Attribute"></a><h2> <span class="mw-headline"> Derived Simple Attribute </span></h2><p>The example in this topic shows the new class ATTRIB_COL, which is derived from the organization class ATTRIB_ABC. ATTRIB_COL contains an integer that denotes one of eight colors. The attribute is attached to a body.</p><a name="Color_Attribute_Header_File"></a><h3> <span class="mw-headline"> Color Attribute Header File </span></h3><p>To create a header (color_attrib.hxx) file for ATTRIB_COL: </p><ol><li> Include the organization attribute classs header file.</li><li> Declare the global, dynamically assigned integer identifier for this attribute class.</li><li> Declare the identification level of this data type to be one level removed from the organization attribute class.</li><li> Declare that ATTRIB_COL is derived from ATTRIB_ABC.</li><li> Declare an integer that defines the color. (This is the only data for the class.)</li><li> Enter a constructor to create a color attribute for a given color and attach it to a given entity. A constructor that takes zero arguments must be provided for the save/restore functions. The constructor shown in the following example takes zero arguments because all arguments are defaulted. This is the recommended way of providing both the zero argument and standard constructor, rather than writing multiple constructors.</li><li> Create the member access (get) and setting (set) functions.</li><li> Prototype merge_owner and replace_owner, as these notification methods are to be implemented directly. (These methods are to be implemented directly because none of the predefined merge or replace actions meet your application needs.)</li><li> Call the ATTRIB_FUNCTIONS macro to declare the functions required to complete the declaration of an attribute. The macro includes declarations for all ENTITY virtual functions, including make_copy, identity, type_name, size, and debug_ent. The macro also includes the declarations for the functions to save, restore, and copy the attribute.</li></ol><p>This example shows what a color attribute file (color_attrib.hxx) could look like.</p><a name="C.2B.2B_Example"></a><h4> <span class="mw-headline"> C++ Example </span></h4><pre class="source-cpp"><span class="kw2">#if</span> !defined<span class="br0">(</span> ATTRIB_COL_CLASS <span class="br0">)</span><span class="kw2">#define</span> ATTRIB_COL_CLASS<span class="kw2">#include</span> <span class="st0">"at_abc.hxx"</span><span class="kw4">extern</span> <span class="kw4">int</span> ATTRIB_COL_TYPE;<span class="kw2">#define</span> <span class="kw7">ATTRIB_COL_LEVEL</span> <span class="br0">(</span> ATTRIB_ABC_LEVEL + <span class="nu0">1</span> <span class="br0">)</span> <span class="kw2">class</span> <span class="kw7">ATTRIB_COL</span> : <span class="kw2">public</span> ATTRIB_ABC <span class="br0">{</span> <span class="kw4">int</span> color_data;<span class="kw2">public</span>: <span class="kw7">ATTRIB_COL</span><span class="br0">(</span> <span class="kw7">ENTITY</span> * = <span class="kw2">NULL</span>, <span class="kw4">int</span> = <span class="nu0">0</span> <span class="br0">)</span>; <span class="kw4">int</span> color <span class="br0">(</span><span class="br0">)</span> <span class="kw4">const</span> <span class="br0">{</span> <span class="kw1">return</span> color_data; <span class="br0">}</span> <span class="kw4">void</span> set_color<span class="br0">(</span> <span class="kw4">int</span> <span class="br0">)</span>; <span class="kw7">ATTRIB_FUNCTIONS</span><span class="br0">(</span> <span class="kw7">ATTRIB_COL</span>, KERN <span class="br0">)</span>; <span class="kw4">void</span> merge_owner<span class="br0">(</span> <span class="kw7">ENTITY</span> *, <span class="kw5">logical</span> <span class="br0">)</span>; <span class="kw4">void</span> replace_owner<span class="br0">(</span> <span class="kw7">ENTITY</span> *, <span class="kw5">logical</span> <span class="br0">)</span>;<span class="br0">}</span>;<span class="kw2">#endif</span></pre><p>Example. color_attrib.hxx Color Attribute Header File (A)</p><a name="Color_Attribute_Implementation_File"></a><h3> <span class="mw-headline"> Color Attribute Implementation File </span></h3><p>To create a color attribute implementation (color_attrib.cxx) file:</p><ol><li> Include necessary system header files.</li><li> Include the header file declaring this specific attribute.</li><li> Include the header files necessary to define new entities.</li><li> Define THIS, THIS_LIB, PARENT, and PARENT_LIB macros to make subsequent definitions of this attribute and its parent easier.</li><li> Define the identifier used externally to identify a particular entity type.</li><li> Call macros used to implement the standard attribute methods and data. (These macros are discussed elsewhere in this section.)</li><li> Write any additional functions that were declared in the .hxx file.<ol><li> Define the constructor. The example calls the ATTRIB constructor to set the owning entity pointer then sets the member data. It also sets the copy_owner and split_owner actions as desired.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -