Mercurial > projects > hoofbaby
comparison deps/Platinum/Source/Core/PltArgument.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Platinum - Action Argument | |
4 | | |
5 | Copyright (c) 2004-2008, Plutinosoft, LLC. | |
6 | All rights reserved. | |
7 | http://www.plutinosoft.com | |
8 | | |
9 | This program is free software; you can redistribute it and/or | |
10 | modify it under the terms of the GNU General Public License | |
11 | as published by the Free Software Foundation; either version 2 | |
12 | of the License, or (at your option) any later version. | |
13 | | |
14 | OEMs, ISVs, VARs and other distributors that combine and | |
15 | distribute commercially licensed software with Platinum software | |
16 | and do not wish to distribute the source code for the commercially | |
17 | licensed software under version 2, or (at your option) any later | |
18 | version, of the GNU General Public License (the "GPL") must enter | |
19 | into a commercial license agreement with Plutinosoft, LLC. | |
20 | | |
21 | This program is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | | |
26 | You should have received a copy of the GNU General Public License | |
27 | along with this program; see the file LICENSE.txt. If not, write to | |
28 | the Free Software Foundation, Inc., | |
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
30 | http://www.gnu.org/licenses/gpl-2.0.html | |
31 | | |
32 ****************************************************************/ | |
33 | |
34 /*---------------------------------------------------------------------- | |
35 | includes | |
36 +---------------------------------------------------------------------*/ | |
37 #include "PltArgument.h" | |
38 #include "PltStateVariable.h" | |
39 #include "PltXmlHelper.h" | |
40 #include "PltAction.h" | |
41 | |
42 NPT_SET_LOCAL_LOGGER("platinum.core.argument") | |
43 | |
44 /*---------------------------------------------------------------------- | |
45 | PLT_ArgumentDesc::PLT_ArgumentDesc | |
46 +---------------------------------------------------------------------*/ | |
47 PLT_ArgumentDesc::PLT_ArgumentDesc(const char* name, | |
48 const char* dir, | |
49 PLT_StateVariable* variable, | |
50 bool has_ret) : | |
51 m_Name(name), | |
52 m_Direction(dir), | |
53 m_RelatedStateVariable(variable), | |
54 m_HasReturnValue(has_ret) | |
55 { | |
56 } | |
57 | |
58 /*---------------------------------------------------------------------- | |
59 | PLT_ArgumentDesc::GetSCPDXML | |
60 +---------------------------------------------------------------------*/ | |
61 NPT_Result | |
62 PLT_ArgumentDesc::GetSCPDXML(NPT_XmlElementNode* node) | |
63 { | |
64 NPT_XmlElementNode* argument = new NPT_XmlElementNode("argument"); | |
65 NPT_CHECK_SEVERE(node->AddChild(argument)); | |
66 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument, "name", m_Name)); | |
67 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument, "direction", m_Direction)); | |
68 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument, "relatedStateVariable", m_RelatedStateVariable->GetName())); | |
69 | |
70 if (m_HasReturnValue) { | |
71 NPT_CHECK_SEVERE(argument->AddChild(new NPT_XmlElementNode("retval"))); | |
72 } | |
73 | |
74 return NPT_SUCCESS; | |
75 } | |
76 | |
77 /*---------------------------------------------------------------------- | |
78 | PLT_Argument::CreateArgument | |
79 +---------------------------------------------------------------------*/ | |
80 NPT_Result | |
81 PLT_Argument::CreateArgument(PLT_ActionDesc* action_desc, | |
82 const char* name, | |
83 const char* value, | |
84 PLT_Argument*& arg) | |
85 { | |
86 // reset output params first | |
87 arg = NULL; | |
88 | |
89 PLT_ArgumentDesc* arg_desc = action_desc->GetArgumentDesc(name); | |
90 if (!arg_desc) return NPT_ERROR_INVALID_PARAMETERS; | |
91 | |
92 PLT_Argument* new_arg = new PLT_Argument(arg_desc); | |
93 if (NPT_FAILED(new_arg->SetValue(value))) { | |
94 delete new_arg; | |
95 return NPT_ERROR_INVALID_PARAMETERS; | |
96 } | |
97 | |
98 arg = new_arg; | |
99 return NPT_SUCCESS; | |
100 } | |
101 | |
102 /*---------------------------------------------------------------------- | |
103 | PLT_Argument::PLT_Argument | |
104 +---------------------------------------------------------------------*/ | |
105 PLT_Argument::PLT_Argument(PLT_ArgumentDesc* arg_desc) : | |
106 m_ArgDesc(arg_desc) | |
107 { | |
108 | |
109 } | |
110 | |
111 /*---------------------------------------------------------------------- | |
112 | PLT_Argument::SetValue | |
113 +---------------------------------------------------------------------*/ | |
114 NPT_Result | |
115 PLT_Argument::SetValue(const char* value) | |
116 { | |
117 NPT_CHECK_SEVERE(ValidateValue(value)); | |
118 | |
119 m_Value = value; | |
120 return NPT_SUCCESS; | |
121 } | |
122 | |
123 /*---------------------------------------------------------------------- | |
124 | PLT_Argument::GetValue | |
125 +---------------------------------------------------------------------*/ | |
126 const NPT_String& | |
127 PLT_Argument::GetValue() | |
128 { | |
129 return m_Value; | |
130 } | |
131 | |
132 /*---------------------------------------------------------------------- | |
133 | PLT_Argument::ValidateValue | |
134 +---------------------------------------------------------------------*/ | |
135 NPT_Result | |
136 PLT_Argument::ValidateValue(const char* value) | |
137 { | |
138 if (m_ArgDesc->GetRelatedStateVariable()) { | |
139 return m_ArgDesc->GetRelatedStateVariable()->ValidateValue(value); | |
140 } | |
141 return NPT_SUCCESS; | |
142 } |