Feature.C 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. // $XConsortium: Feature.cc /main/3 1996/06/11 17:06:39 cde-hal $
  24. #include "SymTab.h"
  25. #include "Feature.h"
  26. #include "FeatureValue.h"
  27. #include <assert.h>
  28. #include <stdarg.h>
  29. Feature::Feature(const Symbol &name, FeatureValue *value)
  30. : f_name(name),
  31. f_value(value)
  32. {
  33. }
  34. Feature::Feature(const Feature &orig_feature)
  35. : f_name(orig_feature.name()),
  36. f_value(orig_feature.value()->clone())
  37. {
  38. }
  39. unsigned int Feature::operator==(const Feature &f )
  40. {
  41. return f.name() == f_name;
  42. }
  43. Feature::~Feature()
  44. {
  45. delete f_value ;
  46. }
  47. FeatureValue *
  48. Feature::evaluate() const
  49. {
  50. return f_value->evaluate();
  51. }
  52. // /////////////////////////////////////////////////////////////////////////
  53. // Printing
  54. // /////////////////////////////////////////////////////////////////////////
  55. ostream &operator << (ostream &o, const Feature &f)
  56. {
  57. return f.print(o);
  58. }
  59. ostream &
  60. Feature::print(ostream &o) const
  61. {
  62. return o << f_name << ": " << *f_value ;
  63. }
  64. void
  65. Feature::merge(const Feature &feature_to_merge)
  66. {
  67. assert(f_name == feature_to_merge.name());
  68. if (*f_value == *feature_to_merge.value())
  69. ;
  70. else
  71. {
  72. FeatureValue *new_value = f_value->merge(*feature_to_merge.value());
  73. delete f_value ;
  74. f_value = new_value ;
  75. }
  76. }