PageRenderTime 64ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ThirdParty/Prebuild/branches/Prebuild-cjac/src/Core/Nodes/OptionsNode.cs

https://bitbucket.org/VirtualReality/libs
C# | 655 lines | 445 code | 82 blank | 128 comment | 16 complexity | 7bec2270ecc91b200f3e9e66e8755085 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, BSD-3-Clause
  1. #region BSD License
  2. /*
  3. Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
  4. Redistribution and use in source and binary forms, with or without modification, are permitted
  5. provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice, this list of conditions
  7. and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
  9. and the following disclaimer in the documentation and/or other materials provided with the
  10. distribution.
  11. * The name of the author may not be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  14. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  17. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  19. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. */
  21. #endregion
  22. #region CVS Information
  23. /*
  24. * $Source$
  25. * $Author: jendave $
  26. * $Date: 2007-01-08 10:55:40 -0600 (Mon, 08 Jan 2007) $
  27. * $Revision: 197 $
  28. */
  29. #endregion
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.Reflection;
  34. using System.Xml;
  35. using Prebuild.Core.Attributes;
  36. using Prebuild.Core.Interfaces;
  37. using Prebuild.Core.Utilities;
  38. namespace Prebuild.Core.Nodes
  39. {
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. [DataNode("Options")]
  44. public class OptionsNode : DataNode
  45. {
  46. #region Fields
  47. private static Hashtable m_OptionFields;
  48. [OptionNode("CompilerDefines")]
  49. private string m_CompilerDefines = "";
  50. /// <summary>
  51. ///
  52. /// </summary>
  53. public string CompilerDefines
  54. {
  55. get
  56. {
  57. return m_CompilerDefines;
  58. }
  59. set
  60. {
  61. m_CompilerDefines = value;
  62. }
  63. }
  64. [OptionNode("OptimizeCode")]
  65. private bool m_OptimizeCode;
  66. /// <summary>
  67. ///
  68. /// </summary>
  69. public bool OptimizeCode
  70. {
  71. get
  72. {
  73. return m_OptimizeCode;
  74. }
  75. set
  76. {
  77. m_OptimizeCode = value;
  78. }
  79. }
  80. [OptionNode("CheckUnderflowOverflow")]
  81. private bool m_CheckUnderflowOverflow;
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. public bool CheckUnderflowOverflow
  86. {
  87. get
  88. {
  89. return m_CheckUnderflowOverflow;
  90. }
  91. set
  92. {
  93. m_CheckUnderflowOverflow = value;
  94. }
  95. }
  96. [OptionNode("AllowUnsafe")]
  97. private bool m_AllowUnsafe;
  98. /// <summary>
  99. ///
  100. /// </summary>
  101. public bool AllowUnsafe
  102. {
  103. get
  104. {
  105. return m_AllowUnsafe;
  106. }
  107. set
  108. {
  109. m_AllowUnsafe = value;
  110. }
  111. }
  112. [OptionNode("PreBuildEvent")]
  113. private string m_PreBuildEvent;
  114. /// <summary>
  115. ///
  116. /// </summary>
  117. public string PreBuildEvent
  118. {
  119. get
  120. {
  121. return m_PreBuildEvent;
  122. }
  123. set
  124. {
  125. m_PreBuildEvent = value;
  126. }
  127. }
  128. [OptionNode("PostBuildEvent")]
  129. private string m_PostBuildEvent;
  130. /// <summary>
  131. ///
  132. /// </summary>
  133. public string PostBuildEvent
  134. {
  135. get
  136. {
  137. return m_PostBuildEvent;
  138. }
  139. set
  140. {
  141. m_PostBuildEvent = value;
  142. }
  143. }
  144. [OptionNode("PreBuildEventArgs")]
  145. private string m_PreBuildEventArgs;
  146. /// <summary>
  147. ///
  148. /// </summary>
  149. public string PreBuildEventArgs
  150. {
  151. get
  152. {
  153. return m_PreBuildEventArgs;
  154. }
  155. set
  156. {
  157. m_PreBuildEventArgs = value;
  158. }
  159. }
  160. [OptionNode("PostBuildEventArgs")]
  161. private string m_PostBuildEventArgs;
  162. /// <summary>
  163. ///
  164. /// </summary>
  165. public string PostBuildEventArgs
  166. {
  167. get
  168. {
  169. return m_PostBuildEventArgs;
  170. }
  171. set
  172. {
  173. m_PostBuildEventArgs = value;
  174. }
  175. }
  176. [OptionNode("RunPostBuildEvent")]
  177. private string m_RunPostBuildEvent;
  178. /// <summary>
  179. ///
  180. /// </summary>
  181. public string RunPostBuildEvent
  182. {
  183. get
  184. {
  185. return m_RunPostBuildEvent;
  186. }
  187. set
  188. {
  189. m_RunPostBuildEvent = value;
  190. }
  191. }
  192. [OptionNode("RunScript")]
  193. private string m_RunScript;
  194. /// <summary>
  195. ///
  196. /// </summary>
  197. public string RunScript
  198. {
  199. get
  200. {
  201. return m_RunScript;
  202. }
  203. set
  204. {
  205. m_RunScript = value;
  206. }
  207. }
  208. [OptionNode("WarningLevel")]
  209. private int m_WarningLevel = 4;
  210. /// <summary>
  211. ///
  212. /// </summary>
  213. public int WarningLevel
  214. {
  215. get
  216. {
  217. return m_WarningLevel;
  218. }
  219. set
  220. {
  221. m_WarningLevel = value;
  222. }
  223. }
  224. [OptionNode("WarningsAsErrors")]
  225. private bool m_WarningsAsErrors;
  226. /// <summary>
  227. ///
  228. /// </summary>
  229. public bool WarningsAsErrors
  230. {
  231. get
  232. {
  233. return m_WarningsAsErrors;
  234. }
  235. set
  236. {
  237. m_WarningsAsErrors = value;
  238. }
  239. }
  240. [OptionNode("SuppressWarnings")]
  241. private string m_SuppressWarnings = "";
  242. /// <summary>
  243. ///
  244. /// </summary>
  245. public string SuppressWarnings
  246. {
  247. get
  248. {
  249. return m_SuppressWarnings;
  250. }
  251. set
  252. {
  253. m_SuppressWarnings = value;
  254. }
  255. }
  256. [OptionNode("OutputPath")]
  257. private string m_OutputPath = "bin/";
  258. /// <summary>
  259. ///
  260. /// </summary>
  261. public string OutputPath
  262. {
  263. get
  264. {
  265. return m_OutputPath;
  266. }
  267. set
  268. {
  269. m_OutputPath = value;
  270. }
  271. }
  272. [OptionNode("GenerateDocumentation")]
  273. private bool m_GenerateDocumentation;
  274. /// <summary>
  275. ///
  276. /// </summary>
  277. public bool GenerateDocumentation
  278. {
  279. get
  280. {
  281. return m_GenerateDocumentation;
  282. }
  283. set
  284. {
  285. m_GenerateDocumentation = value;
  286. }
  287. }
  288. [OptionNode("GenerateXmlDocFile")]
  289. private bool m_GenerateXmlDocFile;
  290. /// <summary>
  291. ///
  292. /// </summary>
  293. public bool GenerateXmlDocFile
  294. {
  295. get
  296. {
  297. return m_GenerateXmlDocFile;
  298. }
  299. set
  300. {
  301. m_GenerateXmlDocFile = value;
  302. }
  303. }
  304. [OptionNode("XmlDocFile")]
  305. private string m_XmlDocFile = "";
  306. /// <summary>
  307. ///
  308. /// </summary>
  309. public string XmlDocFile
  310. {
  311. get
  312. {
  313. return m_XmlDocFile;
  314. }
  315. set
  316. {
  317. m_XmlDocFile = value;
  318. }
  319. }
  320. [OptionNode("KeyFile")]
  321. private string m_KeyFile = "";
  322. /// <summary>
  323. ///
  324. /// </summary>
  325. public string KeyFile
  326. {
  327. get
  328. {
  329. return m_KeyFile;
  330. }
  331. set
  332. {
  333. m_KeyFile = value;
  334. }
  335. }
  336. [OptionNode("DebugInformation")]
  337. private bool m_DebugInformation;
  338. /// <summary>
  339. ///
  340. /// </summary>
  341. public bool DebugInformation
  342. {
  343. get
  344. {
  345. return m_DebugInformation;
  346. }
  347. set
  348. {
  349. m_DebugInformation = value;
  350. }
  351. }
  352. [OptionNode("RegisterComInterop")]
  353. private bool m_RegisterComInterop;
  354. /// <summary>
  355. ///
  356. /// </summary>
  357. public bool RegisterComInterop
  358. {
  359. get
  360. {
  361. return m_RegisterComInterop;
  362. }
  363. set
  364. {
  365. m_RegisterComInterop = value;
  366. }
  367. }
  368. [OptionNode("RemoveIntegerChecks")]
  369. private bool m_RemoveIntegerChecks;
  370. /// <summary>
  371. ///
  372. /// </summary>
  373. public bool RemoveIntegerChecks
  374. {
  375. get
  376. {
  377. return m_RemoveIntegerChecks;
  378. }
  379. set
  380. {
  381. m_RemoveIntegerChecks = value;
  382. }
  383. }
  384. [OptionNode("IncrementalBuild")]
  385. private bool m_IncrementalBuild;
  386. /// <summary>
  387. ///
  388. /// </summary>
  389. public bool IncrementalBuild
  390. {
  391. get
  392. {
  393. return m_IncrementalBuild;
  394. }
  395. set
  396. {
  397. m_IncrementalBuild = value;
  398. }
  399. }
  400. [OptionNode("BaseAddress")]
  401. private string m_BaseAddress = "285212672";
  402. /// <summary>
  403. ///
  404. /// </summary>
  405. public string BaseAddress
  406. {
  407. get
  408. {
  409. return m_BaseAddress;
  410. }
  411. set
  412. {
  413. m_BaseAddress = value;
  414. }
  415. }
  416. [OptionNode("FileAlignment")]
  417. private int m_FileAlignment = 4096;
  418. /// <summary>
  419. ///
  420. /// </summary>
  421. public int FileAlignment
  422. {
  423. get
  424. {
  425. return m_FileAlignment;
  426. }
  427. set
  428. {
  429. m_FileAlignment = value;
  430. }
  431. }
  432. [OptionNode("NoStdLib")]
  433. private bool m_NoStdLib;
  434. /// <summary>
  435. ///
  436. /// </summary>
  437. public bool NoStdLib
  438. {
  439. get
  440. {
  441. return m_NoStdLib;
  442. }
  443. set
  444. {
  445. m_NoStdLib = value;
  446. }
  447. }
  448. private StringCollection m_FieldsDefined;
  449. #endregion
  450. #region Constructors
  451. /// <summary>
  452. /// Initializes the <see cref="OptionsNode"/> class.
  453. /// </summary>
  454. static OptionsNode()
  455. {
  456. Type t = typeof(OptionsNode);
  457. m_OptionFields = new Hashtable();
  458. foreach(FieldInfo f in t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
  459. {
  460. object[] attrs = f.GetCustomAttributes(typeof(OptionNodeAttribute), false);
  461. if(attrs == null || attrs.Length < 1)
  462. {
  463. continue;
  464. }
  465. OptionNodeAttribute ona = (OptionNodeAttribute)attrs[0];
  466. m_OptionFields[ona.NodeName] = f;
  467. }
  468. }
  469. /// <summary>
  470. /// Initializes a new instance of the <see cref="OptionsNode"/> class.
  471. /// </summary>
  472. public OptionsNode()
  473. {
  474. m_FieldsDefined = new StringCollection();
  475. }
  476. #endregion
  477. #region Properties
  478. /// <summary>
  479. /// Gets the <see cref="Object"/> at the specified index.
  480. /// </summary>
  481. /// <value></value>
  482. public object this[string index]
  483. {
  484. get
  485. {
  486. if(!m_OptionFields.ContainsKey(index))
  487. {
  488. return null;
  489. }
  490. FieldInfo f = (FieldInfo)m_OptionFields[index];
  491. return f.GetValue(this);
  492. }
  493. }
  494. /// <summary>
  495. /// Gets the <see cref="Object"/> at the specified index.
  496. /// </summary>
  497. /// <value></value>
  498. public object this[string index, object defaultValue]
  499. {
  500. get
  501. {
  502. object valueObject = this[index];
  503. if(valueObject != null && valueObject is string && ((string)valueObject).Length == 0)
  504. {
  505. return defaultValue;
  506. }
  507. return valueObject;
  508. }
  509. }
  510. #endregion
  511. #region Private Methods
  512. private void FlagDefined(string name)
  513. {
  514. if(!m_FieldsDefined.Contains(name))
  515. {
  516. m_FieldsDefined.Add(name);
  517. }
  518. }
  519. private void SetOption(string nodeName, string val)
  520. {
  521. lock(m_OptionFields)
  522. {
  523. if(!m_OptionFields.ContainsKey(nodeName))
  524. {
  525. return;
  526. }
  527. FieldInfo f = (FieldInfo)m_OptionFields[nodeName];
  528. f.SetValue(this, Helper.TranslateValue(f.FieldType, val));
  529. FlagDefined(f.Name);
  530. }
  531. }
  532. #endregion
  533. #region Public Methods
  534. /// <summary>
  535. /// Parses the specified node.
  536. /// </summary>
  537. /// <param name="node">The node.</param>
  538. public override void Parse(XmlNode node)
  539. {
  540. if( node == null )
  541. {
  542. throw new ArgumentNullException("node");
  543. }
  544. foreach(XmlNode child in node.ChildNodes)
  545. {
  546. SetOption(child.Name, Helper.InterpolateForEnvironmentVariables(child.InnerText));
  547. }
  548. }
  549. /// <summary>
  550. /// Copies to.
  551. /// </summary>
  552. /// <param name="opt">The opt.</param>
  553. public void CopyTo(OptionsNode opt)
  554. {
  555. if(opt == null)
  556. {
  557. return;
  558. }
  559. foreach(FieldInfo f in m_OptionFields.Values)
  560. {
  561. if(m_FieldsDefined.Contains(f.Name))
  562. {
  563. f.SetValue(opt, f.GetValue(this));
  564. opt.m_FieldsDefined.Add(f.Name);
  565. }
  566. }
  567. }
  568. #endregion
  569. }
  570. }