+++ /dev/null
-/*\r
- * \r
- * Copyright 2001-2004 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks.types;\r
-import java.util.Vector;\r
-\r
-import net.sf.antcontrib.cpptasks.CUtil;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.types.DataType;\r
-import org.apache.tools.ant.types.Reference;\r
-/**\r
- * Set of preprocessor macro defines and undefines.\r
- * \r
- * @author Mark A Russell <a\r
- * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com\r
- * </a>\r
- * @author Adam Murdoch\r
- */\r
-public class DefineSet extends DataType {\r
- private Vector defineList = new Vector();\r
- private String ifCond = null;\r
- private String unlessCond = null;\r
- /**\r
- * \r
- * Adds a define element.\r
- * \r
- * @throws BuildException\r
- * if reference\r
- */\r
- public void addDefine(DefineArgument arg) throws BuildException {\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- defineList.addElement(arg);\r
- }\r
- /** Adds defines/undefines. */\r
- private void addDefines(String[] defs, boolean isDefine) {\r
- for (int i = 0; i < defs.length; i++) {\r
- UndefineArgument def;\r
- if (isDefine) {\r
- def = new DefineArgument();\r
- } else {\r
- def = new UndefineArgument();\r
- }\r
- def.setName(defs[i]);\r
- defineList.addElement(def);\r
- }\r
- }\r
- /**\r
- * \r
- * Adds an undefine element.\r
- * \r
- * @throws BuildException\r
- * if reference\r
- */\r
- public void addUndefine(UndefineArgument arg) throws BuildException {\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- defineList.addElement(arg);\r
- }\r
- public void execute() throws org.apache.tools.ant.BuildException {\r
- throw new org.apache.tools.ant.BuildException(\r
- "Not an actual task, but looks like one for documentation purposes");\r
- }\r
- /** Returns the defines and undefines in this set. */\r
- public UndefineArgument[] getDefines() throws BuildException {\r
- if (isReference()) {\r
- DefineSet defset = (DefineSet) getCheckedRef(DefineSet.class,\r
- "DefineSet");\r
- return defset.getDefines();\r
- } else {\r
- if (isActive()) {\r
- UndefineArgument[] defs = new UndefineArgument[defineList\r
- .size()];\r
- defineList.copyInto(defs);\r
- return defs;\r
- } else {\r
- return new UndefineArgument[0];\r
- }\r
- }\r
- }\r
- /**\r
- * Returns true if the define's if and unless conditions (if any) are\r
- * satisfied.\r
- * \r
- * @exception BuildException\r
- * throws build exception if name is not set\r
- */\r
- public final boolean isActive() throws BuildException {\r
- return CUtil.isActive(getProject(), ifCond, unlessCond);\r
- }\r
- /**\r
- * A comma-separated list of preprocessor macros to define. Use nested\r
- * define elements to define macro values.\r
- * \r
- * @param defList\r
- * comma-separated list of preprocessor macros\r
- * @throws BuildException\r
- * throw if defineset is a reference\r
- */\r
- public void setDefine(CUtil.StringArrayBuilder defList)\r
- throws BuildException {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- addDefines(defList.getValue(), true);\r
- }\r
- /**\r
- * Sets a description of the current data type.\r
- */\r
- public void setDescription(String desc) {\r
- super.setDescription(desc);\r
- }\r
- /**\r
- * Sets an id that can be used to reference this element.\r
- * \r
- * @param id\r
- * id\r
- */\r
- public void setId(String id) {\r
- //\r
- // this is actually accomplished by a different\r
- // mechanism, but we can document it\r
- //\r
- }\r
- /**\r
- * Sets the property name for the 'if' condition.\r
- * \r
- * The define will be ignored unless the property is defined.\r
- * \r
- * The value of the property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") will throw an exception when\r
- * evaluated.\r
- * \r
- * @param propName\r
- * property name\r
- */\r
- public final void setIf(String propName) {\r
- ifCond = propName;\r
- }\r
- /**\r
- * Specifies that this element should behave as if the content of the\r
- * element with the matching id attribute was inserted at this location. If\r
- * specified, no other attributes or child content should be specified,\r
- * other than "description".\r
- * \r
- */\r
- public void setRefid(Reference r) throws BuildException {\r
- if (!defineList.isEmpty()) {\r
- throw tooManyAttributes();\r
- }\r
- super.setRefid(r);\r
- }\r
- /**\r
- * A comma-separated list of preprocessor macros to undefine.\r
- * \r
- * @param undefList\r
- * comma-separated list of preprocessor macros\r
- * @throws BuildException\r
- * throw if defineset is a reference\r
- */\r
- public void setUndefine(CUtil.StringArrayBuilder undefList)\r
- throws BuildException {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- addDefines(undefList.getValue(), false);\r
- }\r
- /**\r
- * Set the property name for the 'unless' condition.\r
- * \r
- * If named property is set, the define will be ignored.\r
- * \r
- * The value of the property is insignificant, but values that would imply\r
- * misinterpretation ("false", "no") of the behavior will throw an\r
- * exception when evaluated.\r
- * \r
- * @param propName\r
- * name of property\r
- */\r
- public final void setUnless(String propName) {\r
- unlessCond = propName;\r
- }\r
-}\r