/0.82/Src/Framework/Table.cs

# · C# · 1163 lines · 572 code · 140 blank · 451 comment · 88 complexity · 634b66d8bbaeeeb21e1d3911f0e54c79 MD5 · raw file

  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="Table.cs" company="Open Trader">
  3. // Copyright (c) David Denis (david.denis@systemathics.com)
  4. // </copyright>
  5. // <summary>
  6. // | Open Trader - The Open Source Systematic Trading Platform
  7. // |
  8. // | This program is free software: you can redistribute it and/or modify
  9. // | it under the terms of the GNU General Public License as published by
  10. // | the Free Software Foundation, either version 2 of the License, or
  11. // | (at your option) any later version.
  12. // |
  13. // | This program is distributed in the hope that it will be useful,
  14. // | but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // | GNU General Public License for more details.
  17. // |
  18. // | You should have received a copy of the GNU General Public License
  19. // | along with this program. If not, see http://www.gnu.org/licenses
  20. // |
  21. // | Up to date informations about Open Trader can be found at :
  22. // | http://opentrader.org
  23. // | http://opentrader.codeplex.com
  24. // |
  25. // | For professional services, please visit us at :
  26. // | http://www.systemathics.com
  27. // </summary>
  28. // --------------------------------------------------------------------------------------------------------------------
  29. namespace Org.OpenTrader.Framework
  30. {
  31. #region Using Directives
  32. using System;
  33. using System.Collections.Generic;
  34. using System.Linq;
  35. using Org.OpenTrader.Framework.LiveObjects;
  36. #endregion
  37. /// <summary>
  38. /// The table.
  39. /// </summary>
  40. [Serializable]
  41. public class Table
  42. {
  43. #region Constants and Fields
  44. /// <summary>
  45. /// Column list
  46. /// </summary>
  47. private readonly IList<Column> Columns = new List<Column>();
  48. #endregion
  49. #region Properties
  50. /// <summary>
  51. /// Number of Columns
  52. /// </summary>
  53. public int ColCount
  54. {
  55. get
  56. {
  57. return this.Columns.Count;
  58. }
  59. }
  60. /// <summary>
  61. /// Gets ColumnNames.
  62. /// </summary>
  63. public string[] ColumnNames
  64. {
  65. get
  66. {
  67. IList<string> columns = new List<string>();
  68. foreach (var column in this.Columns)
  69. {
  70. columns.Add(column.Name);
  71. }
  72. return columns.ToArray();
  73. }
  74. }
  75. /// <summary>
  76. /// Number of Rows
  77. /// </summary>
  78. public int RowCount
  79. {
  80. get
  81. {
  82. if (this.Columns.Count <= 0)
  83. {
  84. return 0;
  85. }
  86. return this.Columns[0].Nb;
  87. }
  88. }
  89. #endregion
  90. #region Indexers
  91. /// <summary>
  92. /// The this.
  93. /// </summary>
  94. /// <param name="columnIndex">
  95. /// The columnIndex.
  96. /// </param>
  97. public Column this[int columnIndex]
  98. {
  99. get
  100. {
  101. if (columnIndex >= 0 && columnIndex < this.ColCount)
  102. {
  103. return this.Columns[columnIndex];
  104. }
  105. return null;
  106. }
  107. }
  108. /// <summary>
  109. /// The this.
  110. /// </summary>
  111. /// <param name="rowIndex">
  112. /// The row.
  113. /// </param>
  114. /// <param name="columnIndex">
  115. /// The column.
  116. /// </param>
  117. /// <returns>
  118. /// </returns>
  119. public Cell this[int rowIndex, int columnIndex]
  120. {
  121. get
  122. {
  123. var column = this[columnIndex];
  124. return column == null ? null : column[rowIndex];
  125. }
  126. }
  127. /// <summary>
  128. /// The this.
  129. /// </summary>
  130. /// <param name="rowIndex">
  131. /// The row index.
  132. /// </param>
  133. /// <param name="columnName">
  134. /// The column name.
  135. /// </param>
  136. public Cell this[int rowIndex, string columnName]
  137. {
  138. get
  139. {
  140. var colIndex = this.ColumnIndex(columnName);
  141. if (colIndex < 0)
  142. {
  143. return null;
  144. }
  145. var column = this[colIndex];
  146. return column == null ? null : column[rowIndex];
  147. }
  148. }
  149. #endregion
  150. #region Public Methods
  151. /// <summary>
  152. /// Add a column
  153. /// </summary>
  154. /// <param name="c">
  155. /// not null
  156. /// </param>
  157. /// <returns>
  158. /// The add.
  159. /// </returns>
  160. public bool Add(Column c)
  161. {
  162. // check column
  163. if (c == null)
  164. {
  165. return true;
  166. }
  167. if (this.ColCount == 0)
  168. {
  169. this.Columns.Add(c);
  170. return true;
  171. }
  172. // check nbrow
  173. if (this.RowCount != c.Nb)
  174. {
  175. return false;
  176. }
  177. // no duplicate column
  178. var index = this.ColumnIndex(c.Name);
  179. if (index != -1)
  180. {
  181. return false;
  182. }
  183. // add the column
  184. this.Columns.Add(c);
  185. return true;
  186. }
  187. /// <summary>
  188. /// Add a column
  189. /// </summary>
  190. /// <param name="name">
  191. /// </param>
  192. /// <returns>
  193. /// The add.
  194. /// </returns>
  195. public bool Add(string name)
  196. {
  197. var c = new Column(name);
  198. return this.Add(c);
  199. }
  200. /// <summary>
  201. /// Clear all columns
  202. /// </summary>
  203. public void Clear()
  204. {
  205. this.Columns.Clear();
  206. }
  207. /// <summary>
  208. /// Returns the index of the column having the name equals to name, -1 if not found
  209. /// </summary>
  210. /// <param name="name">
  211. /// </param>
  212. /// <returns>
  213. /// The column index.
  214. /// </returns>
  215. public int ColumnIndex(string name)
  216. {
  217. var i = 0;
  218. foreach (var c in this.Columns)
  219. {
  220. if (c != null)
  221. {
  222. if (c.Name == name)
  223. {
  224. return i;
  225. }
  226. }
  227. i++;
  228. }
  229. return -1;
  230. }
  231. /// <summary>
  232. /// Delete the column at index
  233. /// </summary>
  234. /// <param name="index">
  235. /// </param>
  236. /// <returns>
  237. /// The delete.
  238. /// </returns>
  239. public bool Delete(int index)
  240. {
  241. if (index < 0 || index >= this.ColCount)
  242. {
  243. return false;
  244. }
  245. this.Columns.RemoveAt(index);
  246. return true;
  247. }
  248. /// <summary>
  249. /// Delete nb columns from index
  250. /// </summary>
  251. /// <param name="index">
  252. /// </param>
  253. /// <param name="nb">
  254. /// </param>
  255. /// <returns>
  256. /// The delete.
  257. /// </returns>
  258. public bool Delete(int index, int nb)
  259. {
  260. if (nb <= 0)
  261. {
  262. return false;
  263. }
  264. if (index < 0 || index >= this.ColCount)
  265. {
  266. return false;
  267. }
  268. while (index < this.ColCount && nb > 0)
  269. {
  270. this.Columns.RemoveAt(index);
  271. nb--;
  272. }
  273. return true;
  274. }
  275. /// <summary>
  276. /// Delete the row at rowIndex
  277. /// </summary>
  278. /// <param name="rowindex">
  279. /// </param>
  280. /// <returns>
  281. /// The delete row.
  282. /// </returns>
  283. public bool DeleteRow(int rowindex)
  284. {
  285. if (rowindex < 0 || rowindex >= this.RowCount)
  286. {
  287. return false;
  288. }
  289. foreach (var c in this.Columns)
  290. {
  291. if (c != null)
  292. {
  293. c.Delete(rowindex);
  294. }
  295. }
  296. return true;
  297. }
  298. /// <summary>
  299. /// Delete the row at rowIndex
  300. /// </summary>
  301. /// <param name="rowindex">
  302. /// The rowindex.
  303. /// </param>
  304. /// <param name="nb">
  305. /// </param>
  306. /// <returns>
  307. /// The delete row.
  308. /// </returns>
  309. public bool DeleteRow(int rowindex, int nb)
  310. {
  311. if (nb <= 0)
  312. {
  313. return false;
  314. }
  315. for (var i = 0; i < nb; i++)
  316. {
  317. if (!this.DeleteRow(rowindex))
  318. {
  319. return true;
  320. }
  321. }
  322. return true;
  323. }
  324. /// <summary>
  325. /// Insert column at index
  326. /// </summary>
  327. /// <param name="c">
  328. /// </param>
  329. /// <param name="index">
  330. /// </param>
  331. /// <returns>
  332. /// The insert.
  333. /// </returns>
  334. public bool Insert(Column c, int index)
  335. {
  336. // check index
  337. if (index < 0 || index >= this.ColCount)
  338. {
  339. return false;
  340. }
  341. // check column c
  342. if (c == null)
  343. {
  344. return false;
  345. }
  346. // if first column
  347. if (this.ColCount == 0)
  348. {
  349. this.Columns.Add(c);
  350. return true;
  351. }
  352. // check nbrow
  353. if (this.RowCount != c.Nb)
  354. {
  355. return false;
  356. }
  357. // no duplicate column
  358. var indexcol = this.ColumnIndex(c.Name);
  359. if (indexcol != -1)
  360. {
  361. return false;
  362. }
  363. // insert column
  364. this.Columns.Insert(index, c);
  365. return true;
  366. }
  367. /// <summary>
  368. /// Insert new column
  369. /// </summary>
  370. /// <param name="name">
  371. /// </param>
  372. /// <param name="index">
  373. /// </param>
  374. /// <returns>
  375. /// The insert.
  376. /// </returns>
  377. public bool Insert(string name, int index)
  378. {
  379. var c = new Column(name);
  380. return this.Insert(c, index);
  381. }
  382. #endregion
  383. /// <summary>
  384. /// The cell.
  385. /// </summary>
  386. public class Cell
  387. {
  388. #region Constructors and Destructors
  389. /// <summary>
  390. /// Initializes a new instance of the <see cref="Cell"/> class.
  391. /// </summary>
  392. /// <param name="content">
  393. /// The content.
  394. /// </param>
  395. /// <exception cref="Exception">
  396. /// </exception>
  397. public Cell(object content)
  398. {
  399. if (content == null)
  400. {
  401. throw new Exception("Cell content cannot be null");
  402. }
  403. if (content.GetType() == typeof(string) || content.GetType() == typeof(ConfigurationField.Table))
  404. {
  405. this.Content = content;
  406. }
  407. else
  408. {
  409. throw new Exception("Cell only supports ConfigurationField.Table and string types as valid content");
  410. }
  411. }
  412. #endregion
  413. #region Properties
  414. /// <summary>
  415. /// Gets Content.
  416. /// </summary>
  417. public object Content { get; private set; }
  418. #endregion
  419. #region Operators
  420. /// <summary>
  421. /// The op_ implicit.
  422. /// </summary>
  423. /// <param name="cell">
  424. /// The cell.
  425. /// </param>
  426. /// <returns>
  427. /// </returns>
  428. public static implicit operator TimeSpan?(Cell cell)
  429. {
  430. var toTimeSpan = ConvertToTimeSpan(cell);
  431. return toTimeSpan;
  432. }
  433. /// <summary>
  434. /// The op_ implicit.
  435. /// </summary>
  436. /// <param name="cell">
  437. /// The cell.
  438. /// </param>
  439. /// <returns>
  440. /// </returns>
  441. /// <exception cref="Exception">
  442. /// </exception>
  443. public static implicit operator TimeSpan(Cell cell)
  444. {
  445. var toTimeSpan = ConvertToTimeSpan(cell);
  446. if (toTimeSpan.HasValue)
  447. {
  448. return toTimeSpan.Value;
  449. }
  450. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to TimeSpan", cell.Content));
  451. }
  452. /// <summary>
  453. /// The op_ implicit.
  454. /// </summary>
  455. /// <param name="cell">
  456. /// The cell.
  457. /// </param>
  458. /// <returns>
  459. /// </returns>
  460. public static implicit operator DateTime?(Cell cell)
  461. {
  462. var toDateTime = ConvertToDateTime(cell);
  463. return toDateTime;
  464. }
  465. /// <summary>
  466. /// The op_ implicit.
  467. /// </summary>
  468. /// <param name="cell">
  469. /// The cell.
  470. /// </param>
  471. /// <returns>
  472. /// </returns>
  473. /// <exception cref="Exception">
  474. /// </exception>
  475. public static implicit operator DateTime(Cell cell)
  476. {
  477. var toDateTime = ConvertToDateTime(cell);
  478. if (toDateTime.HasValue)
  479. {
  480. return toDateTime.Value;
  481. }
  482. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to DateTime", cell.Content));
  483. }
  484. /// <summary>
  485. /// The op_ implicit.
  486. /// </summary>
  487. /// <param name="cell">
  488. /// The cell.
  489. /// </param>
  490. /// <returns>
  491. /// </returns>
  492. public static implicit operator string(Cell cell)
  493. {
  494. return cell.Content as string;
  495. }
  496. /// <summary>
  497. /// The op_ implicit.
  498. /// </summary>
  499. /// <param name="cell">
  500. /// The cell.
  501. /// </param>
  502. /// <returns>
  503. /// </returns>
  504. public static implicit operator Table(Cell cell)
  505. {
  506. return ((ConfigurationField.Table)cell.Content).Contents as Table;
  507. }
  508. /// <summary>
  509. /// The op_ implicit.
  510. /// </summary>
  511. /// <param name="cell">
  512. /// The cell.
  513. /// </param>
  514. /// <returns>
  515. /// </returns>
  516. public static implicit operator int(Cell cell)
  517. {
  518. var toInt = ConvertToInt(cell);
  519. if (toInt.HasValue)
  520. {
  521. return toInt.Value;
  522. }
  523. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to int", cell.Content));
  524. }
  525. /// <summary>
  526. /// The op_ implicit.
  527. /// </summary>
  528. /// <param name="cell">
  529. /// The cell.
  530. /// </param>
  531. /// <returns>
  532. /// </returns>
  533. public static implicit operator int?(Cell cell)
  534. {
  535. var toInt = ConvertToInt(cell);
  536. return toInt;
  537. }
  538. /// <summary>
  539. /// The op_ implicit.
  540. /// </summary>
  541. /// <param name="cell">
  542. /// The cell.
  543. /// </param>
  544. /// <returns>
  545. /// </returns>
  546. public static implicit operator double(Cell cell)
  547. {
  548. var toDecimal = ConvertToDecimal(cell);
  549. if (toDecimal.HasValue)
  550. {
  551. return (double)toDecimal.Value;
  552. }
  553. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to decimal", cell.Content));
  554. }
  555. /// <summary>
  556. /// The op_ implicit.
  557. /// </summary>
  558. /// <param name="cell">
  559. /// The cell.
  560. /// </param>
  561. /// <returns>
  562. /// </returns>
  563. public static implicit operator double?(Cell cell)
  564. {
  565. var toDecimal = (double)ConvertToDecimal(cell);
  566. return toDecimal;
  567. }
  568. /// <summary>
  569. /// The op_ implicit.
  570. /// </summary>
  571. /// <param name="cell">
  572. /// The cell.
  573. /// </param>
  574. /// <returns>
  575. /// </returns>
  576. public static implicit operator float(Cell cell)
  577. {
  578. var toDecimal = ConvertToDecimal(cell);
  579. if (toDecimal.HasValue)
  580. {
  581. return (float)toDecimal.Value;
  582. }
  583. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to decimal", cell.Content));
  584. }
  585. /// <summary>
  586. /// The op_ implicit.
  587. /// </summary>
  588. /// <param name="cell">
  589. /// The cell.
  590. /// </param>
  591. /// <returns>
  592. /// </returns>
  593. public static implicit operator float?(Cell cell)
  594. {
  595. var toDecimal = (float)ConvertToDecimal(cell);
  596. return toDecimal;
  597. }
  598. /// <summary>
  599. /// The op_ implicit.
  600. /// </summary>
  601. /// <param name="cell">
  602. /// The cell.
  603. /// </param>
  604. /// <returns>
  605. /// </returns>
  606. public static implicit operator bool(Cell cell)
  607. {
  608. var toBool = ConvertToBool(cell);
  609. if (toBool.HasValue)
  610. {
  611. return toBool.Value;
  612. }
  613. throw new FormatException(string.Format("Conversion failed : {0} is not convertible to bool", cell.Content));
  614. }
  615. /// <summary>
  616. /// The op_ implicit.
  617. /// </summary>
  618. /// <param name="cell">
  619. /// The cell.
  620. /// </param>
  621. /// <returns>
  622. /// </returns>
  623. public static implicit operator bool?(Cell cell)
  624. {
  625. var toBool = ConvertToBool(cell);
  626. return toBool;
  627. }
  628. #endregion
  629. #region Methods
  630. /// <summary>
  631. /// The convert to bool.
  632. /// </summary>
  633. /// <param name="cell">
  634. /// The cell.
  635. /// </param>
  636. /// <returns>
  637. /// </returns>
  638. private static bool? ConvertToBool(Cell cell)
  639. {
  640. bool? toBool = new bool();
  641. try
  642. {
  643. toBool = bool.Parse(cell.Content as string);
  644. }
  645. catch
  646. {
  647. }
  648. return toBool;
  649. }
  650. /// <summary>
  651. /// The convert to date time.
  652. /// </summary>
  653. /// <param name="cell">
  654. /// The cell.
  655. /// </param>
  656. /// <returns>
  657. /// </returns>
  658. private static DateTime? ConvertToDateTime(Cell cell)
  659. {
  660. DateTime? toDateTime = new DateTime();
  661. try
  662. {
  663. toDateTime = DateTime.Parse(cell.Content as string);
  664. }
  665. catch
  666. {
  667. }
  668. return toDateTime;
  669. }
  670. /// <summary>
  671. /// The convert to decimal.
  672. /// </summary>
  673. /// <param name="cell">
  674. /// The cell.
  675. /// </param>
  676. /// <returns>
  677. /// </returns>
  678. private static decimal? ConvertToDecimal(Cell cell)
  679. {
  680. decimal factor = 1;
  681. var content = cell.Content as string;
  682. if (content.EndsWith("%"))
  683. {
  684. factor = 100;
  685. content = content.TrimEnd(new char[] { '%' });
  686. }
  687. decimal? toDecimal = new decimal();
  688. try
  689. {
  690. toDecimal = decimal.Parse(content, Constants.CultureInfo) / factor;
  691. }
  692. catch
  693. {
  694. }
  695. return toDecimal;
  696. }
  697. /// <summary>
  698. /// The convert to int.
  699. /// </summary>
  700. /// <param name="cell">
  701. /// The cell.
  702. /// </param>
  703. /// <returns>
  704. /// </returns>
  705. private static int? ConvertToInt(Cell cell)
  706. {
  707. var content = cell.Content as string;
  708. int? toInt = new int();
  709. try
  710. {
  711. toInt = int.Parse(content, Constants.CultureInfo);
  712. }
  713. catch
  714. {
  715. }
  716. return toInt;
  717. }
  718. /// <summary>
  719. /// The convert to time span.
  720. /// </summary>
  721. /// <param name="cell">
  722. /// The cell.
  723. /// </param>
  724. /// <returns>
  725. /// </returns>
  726. private static TimeSpan? ConvertToTimeSpan(Cell cell)
  727. {
  728. TimeSpan? toTimeSpan = new TimeSpan();
  729. try
  730. {
  731. var times = (cell.Content as string).Split(new[] { ':' });
  732. var hours = int.Parse(times[0]);
  733. var minutes = int.Parse(times[1]);
  734. var seconds = int.Parse(times[2]);
  735. toTimeSpan = new TimeSpan(hours, minutes, seconds);
  736. }
  737. catch
  738. {
  739. }
  740. return toTimeSpan;
  741. }
  742. #endregion
  743. }
  744. /// <summary>
  745. /// The column.
  746. /// </summary>
  747. [Serializable]
  748. public class Column
  749. {
  750. #region Constants and Fields
  751. /// <summary>
  752. /// Columns
  753. /// </summary>
  754. private readonly IList<Cell> Data = new List<Cell>();
  755. #endregion
  756. #region Constructors and Destructors
  757. /// <summary>
  758. /// Initializes a new instance of the <see cref="Column"/> class.
  759. /// Constructor
  760. /// </summary>
  761. /// <param name="name">
  762. /// not null
  763. /// </param>
  764. public Column(string name)
  765. {
  766. this.Name = name;
  767. }
  768. #endregion
  769. #region Properties
  770. /// <summary>
  771. /// Gets Name.
  772. /// </summary>
  773. public string Name { get; private set; }
  774. /// <summary>
  775. /// Nb data
  776. /// </summary>
  777. public int Nb
  778. {
  779. get
  780. {
  781. return this.Data.Count;
  782. }
  783. }
  784. #endregion
  785. #region Indexers
  786. /// <summary>
  787. /// Gets data at index
  788. /// </summary>
  789. /// <param name="index"></param>
  790. /// <returns></returns>
  791. public Cell this[int index]
  792. {
  793. get
  794. {
  795. if (index >= 0 && index < this.Nb)
  796. {
  797. return this.Data[index];
  798. }
  799. return null;
  800. }
  801. set
  802. {
  803. if (index >= 0 && index < this.Nb)
  804. {
  805. this.Data[index] = value;
  806. }
  807. }
  808. }
  809. #endregion
  810. #region Public Methods
  811. /// <summary>
  812. /// Add data
  813. /// </summary>
  814. /// <param name="o">
  815. /// not null
  816. /// </param>
  817. /// <returns>
  818. /// The add.
  819. /// </returns>
  820. public bool Add(Cell o)
  821. {
  822. if (o == null)
  823. {
  824. return false;
  825. }
  826. this.Data.Add(o);
  827. return true;
  828. }
  829. /// <summary>
  830. /// Add data
  831. /// </summary>
  832. /// <param name="o">
  833. /// not null
  834. /// </param>
  835. /// <param name="nb">
  836. /// not null
  837. /// </param>
  838. /// <returns>
  839. /// The add.
  840. /// </returns>
  841. public bool Add(Cell o, int nb)
  842. {
  843. if (nb <= 0)
  844. {
  845. return false;
  846. }
  847. if (o == null)
  848. {
  849. return false;
  850. }
  851. for (var i = 0; i < nb; i++)
  852. {
  853. this.Data.Add(o);
  854. }
  855. return true;
  856. }
  857. /// <summary>
  858. /// Clear the column by removing all data from the list
  859. /// </summary>
  860. public void Clear()
  861. {
  862. this.Data.Clear();
  863. }
  864. /// <summary>
  865. /// Delete value at index
  866. /// </summary>
  867. /// <param name="index">
  868. /// </param>
  869. /// <returns>
  870. /// The delete.
  871. /// </returns>
  872. public bool Delete(int index)
  873. {
  874. if (index < 0 || index >= this.Nb)
  875. {
  876. return false;
  877. }
  878. this.Data.RemoveAt(index);
  879. return true;
  880. }
  881. /// <summary>
  882. /// Delete nb value from index
  883. /// </summary>
  884. /// <param name="index">
  885. /// </param>
  886. /// <param name="nb">
  887. /// The nb.
  888. /// </param>
  889. /// <returns>
  890. /// The delete.
  891. /// </returns>
  892. public bool Delete(int index, int nb)
  893. {
  894. if (nb <= 0)
  895. {
  896. return false;
  897. }
  898. if (index < 0 || index >= this.Nb)
  899. {
  900. return false;
  901. }
  902. while (index < this.Nb && nb > 0)
  903. {
  904. this.Data.RemoveAt(index);
  905. nb--;
  906. }
  907. return true;
  908. }
  909. /// <summary>
  910. /// insert object
  911. /// </summary>
  912. /// <param name="index">
  913. /// not null
  914. /// </param>
  915. /// <param name="o">
  916. /// not null
  917. /// </param>
  918. /// <returns>
  919. /// The insert.
  920. /// </returns>
  921. public bool Insert(int index, Cell o)
  922. {
  923. if (index < 0 || index >= this.Nb)
  924. {
  925. return false;
  926. }
  927. if (o == null)
  928. {
  929. return false;
  930. }
  931. this.Data.Insert(index, o);
  932. return true;
  933. }
  934. /// <summary>
  935. /// insert object
  936. /// </summary>
  937. /// <param name="index">
  938. /// not null
  939. /// </param>
  940. /// <param name="o">
  941. /// not null
  942. /// </param>
  943. /// <param name="nb">
  944. /// not null
  945. /// </param>
  946. /// <returns>
  947. /// The insert.
  948. /// </returns>
  949. public bool Insert(int index, Cell o, int nb)
  950. {
  951. if (index < 0 || index >= this.Nb || nb <= 0)
  952. {
  953. return false;
  954. }
  955. if (o == null)
  956. {
  957. return false;
  958. }
  959. for (var i = 0; i < nb; i++)
  960. {
  961. this.Data.Insert(index, o);
  962. }
  963. return true;
  964. }
  965. /// <summary>
  966. /// Print the column
  967. /// </summary>
  968. public void Print()
  969. {
  970. if (this.Name != null)
  971. {
  972. Stdout.WriteLine(this.Name);
  973. }
  974. else
  975. {
  976. Stdout.WriteLine("Invalid Name");
  977. }
  978. foreach (var o in this.Data)
  979. {
  980. Stdout.WriteLine(o);
  981. }
  982. }
  983. /// <summary>
  984. /// Gets Item as String at index
  985. /// </summary>
  986. /// <param name="index">
  987. /// </param>
  988. /// <returns>
  989. /// The string item.
  990. /// </returns>
  991. public string StringItem(int index)
  992. {
  993. return this[index].ToString();
  994. }
  995. /// <summary>
  996. /// Update value at index
  997. /// </summary>
  998. /// <param name="index">
  999. /// not null
  1000. /// </param>
  1001. /// <param name="o">
  1002. /// not null
  1003. /// </param>
  1004. /// <returns>
  1005. /// The update.
  1006. /// </returns>
  1007. public bool Update(int index, Cell o)
  1008. {
  1009. if (index < 0 || index >= this.Nb)
  1010. {
  1011. return false;
  1012. }
  1013. if (o == null)
  1014. {
  1015. return false;
  1016. }
  1017. this[index] = o;
  1018. return true;
  1019. }
  1020. #endregion
  1021. }
  1022. }
  1023. }