AttributeTree.h
Go to the documentation of this file.
1 // this is a -*- C++ -*- file
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 #ifndef ICL_CORE_CONFIG_ATTRIBUTE_TREE_H_INCLUDED
29 #define ICL_CORE_CONFIG_ATTRIBUTE_TREE_H_INCLUDED
30 
31 #include <fstream>
32 #include <string>
33 
34 #include "icl_core/BaseTypes.h"
36 
37 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
38 # include "icl_core/Deprecate.h"
39 #endif
40 
41 namespace icl_core {
42 namespace config {
43 
44 class AttributeTree;
45 
46 class FilePath
47 {
48 public:
49  FilePath(const char *filename = "")
50  {
51  init(filename);
52  }
53  FilePath(const icl_core::String& filename)
54  {
55  init(filename.c_str());
56  }
57 
59  { }
60 
64  {
66  }
67 
71  {
72  return icl_core::String(m_file, m_file_path_name_split, icl_core::String::npos);
73  }
74 
78  {
79  return m_file;
80  }
81 
86  {
87  return m_pwd;
88  }
89 
93  {
94  return icl_core::String(m_file, m_file_name_extension_split, icl_core::String::npos);
95  }
96 
100  icl_core::String absolutePath(const icl_core::String& filename) const;
101 
105  static bool isRelativePath(const icl_core::String& filename);
106 
109  bool isRelativePath() const
110  {
112  }
113 
118  static icl_core::String normalizePath(const icl_core::String& filename);
119 
127  static icl_core::String exchangeSeparators(const icl_core::String& filename);
128 
131  static icl_core::String getEnvironment(const icl_core::String& var_name);
132 
137  static icl_core::String replaceEnvironment(const icl_core::String& filename);
138 
140 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
141 
150 
155 
160 
165 
169  ICL_CORE_VC_DEPRECATE_STYLE icl_core::String AbsolutePath(const icl_core::String& filename) const
171 
175  ICL_CORE_VC_DEPRECATE_STYLE static bool IsRelativePath(const icl_core::String& filename)
177 
181  ICL_CORE_VC_DEPRECATE_STYLE bool IsRelativePath() const ICL_CORE_GCC_DEPRECATE_STYLE;
182 
186  ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String NormalizePath(const icl_core::String& filename)
188 
194  ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String ExchangeSeparators(const icl_core::String& filename)
196 
200  ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String GetEnvironment(const icl_core::String& var_name)
202 
206  ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String ReplaceEnvironment(const icl_core::String& filename)
208 
209 #endif
210 
212 private:
213  void init(const char *filename);
214 
217  icl_core::String::size_type m_file_path_name_split;
218  icl_core::String::size_type m_file_name_extension_split;
219 };
220 
221 
226 {
227  friend class AttributeTree;
228 
229 public:
230  SubTreeList(AttributeTree *sub_tree = 0, SubTreeList *next = 0);
231  ~SubTreeList();
232  void copy(AttributeTree *parent);
233  void unlinkParent();
234  void unlink(AttributeTree *obsolete_tree);
235  AttributeTree *subTree(const char *description);
236  int contains();
237  void printSubTree(std::ostream& out, int change_style_depth, char *upper_description);
238  void printXmlSubTree(std::ostream& out, const std::string& upper_description);
239  bool changed();
240  AttributeTree *search(const char *description, const char *attribute);
241  AttributeTree *next(AttributeTree *prev);
242  void unmarkChanges();
243 
246  SubTreeList *revertOrder(SubTreeList *new_next = NULL);
247 
251  void newSubTreeList(AttributeTree *new_tree, AttributeTree *after);
252 
254 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
255 
259  ICL_CORE_VC_DEPRECATE_STYLE SubTreeList *RevertOrder(SubTreeList *new_next = NULL)
261 
266  ICL_CORE_VC_DEPRECATE_STYLE void NewSubTreeList(AttributeTree *new_tree, AttributeTree *after)
267  ICL_CORE_GCC_DEPRECATE_STYLE;
268 
269 #endif
270 
272 private:
273  // Forbid copying.
274  SubTreeList(const SubTreeList&);
275  SubTreeList& operator = (const SubTreeList&);
276 
279 };
280 
308 {
309  friend class SubTreeList;
310 
311 public:
314  enum
315  {
316  eOK,
319  eFILE_LOAD_ERROR
320  };
323  AttributeTree(const char *description = 0, AttributeTree *parent = 0);
324 
328  AttributeTree(const AttributeTree& other);
329 
337  AttributeTree(const AttributeTree& other, AttributeTree *parent);
338 
342  ~AttributeTree();
343 
347  void unlink();
348 
352  void unlinkSub();
353 
358  // inline AttributeTree *getSubTree(const char *description)
359  // { return getOrCreateSubTree()->setAttribute(description, 0); }
360 
367  AttributeTree *setAttribute(const char *description, const char *attribute);
368 
372  AttributeTree *setAttribute(const char *description, const char *subdescription, const char *attribute);
373 
378  // inline AttributeTree *setSubAttribute(const char *description, const char *attribute)
379  // { return setAttribute(m_this_description, description, attribute); }
380 
383  char *getAttribute()
384  {
385  return m_this_attribute;
386  }
387 
392  char *getAttribute(const char *description, const char *default_attribute = 0,
393  AttributeTree **subtree = 0);
394 
398  char *getOrSetDefault(const char *description, const char *default_attribute);
399 
403  int save(const char *filename, int change_style_depth = 3, bool unmark_changes = true);
404 
422  int load(const char *filename, bool unmark_changes = true, bool process_include = true,
423  bool load_comments = false, bool preserve_order = false);
424 
427  int get(std::istream &in, bool process_include = true, bool load_comments = false,
428  const FilePath *file_path = NULL);
429 
441  char *newSubNodeDescription(const char *base_description = "");
442 
445  AttributeTree *addNewSubTree();
446 
451  void printSubTree(std::ostream &out, int change_style_depth = 3, const char *upper_description = 0);
452 
455  const char *getDescription() const
456  {
457  return m_this_description;
458  }
459 
462  const char *attribute() const
463  {
464  return m_this_attribute;
465  }
466 
469  void setDescription(const char *description);
470 
473  void setAttribute(const char *attribute);
474 
477  void setComment(const char *comment);
478 
482  AttributeTree *subTree(const char *description);
483 
487  AttributeTree *getSubTree(const char *description);
488 
493  {
494  if (m_subtree_list)
495  {
496  return m_subtree_list->m_sub_tree;
497  }
498  else
499  {
500  return NULL;
501  }
502  }
503 
508  {
509  if (m_subtree_list)
510  {
511  return m_subtree_list->next(subtree);
512  }
513  else
514  {
515  return NULL;
516  }
517  }
518 
523  {
524  return m_parent;
525  }
526 
533  {
534  return addSubTree(subtree, NULL);
535  }
536 
545  {
546  if (m_parent)
547  {
548  return m_parent->addSubTree(nexttree, this);
549  }
550  else
551  {
552  return NULL;
553  }
554  }
555 
562  AttributeTree *search(const char *description, const char *attribute);
563 
567  bool isAttribute(const char *description, const char *attribute = 0);
568 
572  bool changed();
573 
576  void unmarkChanges();
577 
580  int contains();
581 
585  {
586  return m_parent;
587  }
588 
592  {
593  AttributeTree *at = this;
594  for (; at->m_parent; at = at->m_parent) {}
595  return at;
596  }
597 
601  const char *comment();
602 
605  bool hasComment()
606  {
607  return commentAttributeTree() != NULL;
608  }
609 
612  bool isComment();
613 
616  bool hasMultilineComment();
617 
620  bool isMultilineComment();
621 
624  AttributeTree *commentAttributeTree();
625 
631  void appendAttribute(const char *attribute, const char *separator = "")
632  {
633  appendString(m_this_attribute, attribute, separator);
634  }
635 
641  void appendDescription(const char *description, const char *separator = "")
642  {
643  appendString(m_this_description, description, separator);
644  }
645 
648  void revertOrder()
649  {
650  if (m_subtree_list)
651  {
652  m_subtree_list = m_subtree_list->revertOrder();
653  }
654  }
655 
664  static const char *m_file_path_str;
665 
669  const char *getFilePath()
670  {
671  const char *ret = root()->getSpecialAttribute(m_file_path_str);
672  if (!ret)
673  {
674  ret = "";
675  }
676  return ret;
677  }
678 
687  static const char *m_file_name_str;
688 
693  const char *fileName()
694  {
695  const char *ret = root()->getSpecialAttribute(m_file_name_str);
696  if (!ret)
697  {
698  ret = "";
699  }
700  return ret;
701  }
702 
704 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
705 
710 
715 
719  ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SetAttribute(const char *description,
720  const char *attribute)
722 
727  ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SetAttribute(const char *description,
728  const char *subdescription,
729  const char *attribute)
731 
736 
740  ICL_CORE_VC_DEPRECATE_STYLE char *GetAttribute(const char *description,
741  const char *default_attribute = 0,
742  AttributeTree **subtree = 0)
744 
748  ICL_CORE_VC_DEPRECATE_STYLE char *GetOrSetDefault(const char *description,
749  const char *default_attribute)
751 
755  ICL_CORE_VC_DEPRECATE_STYLE int Save(const char *filename, int change_style_depth = 3,
756  bool unmark_changes = true)
758 
762  ICL_CORE_VC_DEPRECATE_STYLE int Load(const char *filename, bool unmark_changes = true,
763  bool process_include = true,
764  bool load_comments = false,
765  bool preserve_order = false)
767 
771  ICL_CORE_VC_DEPRECATE_STYLE int Get(std::istream &in, bool process_include = true,
772  bool load_comments = false,
773  const FilePath *file_path = NULL)
775 
779  ICL_CORE_VC_DEPRECATE_STYLE char *NewSubNodeDescription(const char *base_description = "")
781 
786 
790  ICL_CORE_VC_DEPRECATE_STYLE void PrintSubTree(std::ostream &out,
791  int change_style_depth = 3,
792  const char *upper_description = 0)
794 
798  ICL_CORE_VC_DEPRECATE_STYLE const char *Description() const ICL_CORE_GCC_DEPRECATE_STYLE;
799 
803  ICL_CORE_VC_DEPRECATE_STYLE const char *Attribute() const ICL_CORE_GCC_DEPRECATE_STYLE;
804 
808  ICL_CORE_VC_DEPRECATE_STYLE void SetDescription(const char *description)
810 
814  ICL_CORE_VC_DEPRECATE_STYLE void SetAttribute(const char *attribute) ICL_CORE_GCC_DEPRECATE_STYLE;
815 
819  ICL_CORE_VC_DEPRECATE_STYLE void SetComment(const char *comment) ICL_CORE_GCC_DEPRECATE_STYLE;
820 
824  ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SubTree(const char *description)
826 
830  ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *GetSubTree(const char *description)
832 
837 
843 
848 
854 
860 
866  ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *Search(const char *description, const char *attribute)
868 
873  ICL_CORE_VC_DEPRECATE_STYLE bool IsAttribute(const char *description, const char *attribute = 0)
875 
881 
886 
891 
896 
901 
906 
911 
916 
921 
926 
931 
935  ICL_CORE_VC_DEPRECATE_STYLE void AppendAttribute(const char *attribute, const char *separator = "")
937 
941  ICL_CORE_VC_DEPRECATE_STYLE void AppendDescription(const char *description, const char *separator = "")
943 
948 
954 
960 
961 #endif
962 
964 
965 private:
966  void split(char *&description, char *&sub_description);
967  void appendString(char * &dest, const char *src, const char *separator);
968 
969  // Forbid copying.
970  AttributeTree& operator = (const AttributeTree&);
971 
974  char *getSpecialAttribute(const char *description, AttributeTree **subtree = NULL);
975 
978  AttributeTree *addSubTree(AttributeTree *subtree, AttributeTree *after_node);
979 
982 
985 
986  bool m_changed;
987 };
988 
989 }
990 }
991 
992 #endif
FilePath(const icl_core::String &filename)
Definition: AttributeTree.h:53
void init(const char *filename)
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
std::vector< String > split(const String &str, const String &delimiter)
static icl_core::String replaceEnvironment(const icl_core::String &filename)
#define ICL_CORE_CONFIG_IMPORT_EXPORT
Contains macros to deprecate classes, types, functions and variables.
void appendDescription(const char *description, const char *separator="")
const char * getDescription() const
icl_core::String::size_type m_file_name_extension_split
static const char * m_file_name_str
icl_core::String currentDir() const
Definition: AttributeTree.h:85
AttributeTree * nextSubTree(AttributeTree *subtree)
static icl_core::String normalizePath(const icl_core::String &filename)
AttributeTree * addSubTree(AttributeTree *subtree)
int unlink(const char *filename)
Definition: os_fs.h:52
Contains import/export definitions for the Win32 plattform.
AttributeTree * addNextTree(AttributeTree *nexttree)
icl_core::String::size_type m_file_path_name_split
std::string String
Definition: BaseTypes.h:43
static const char * m_file_path_str
static icl_core::String getEnvironment(const icl_core::String &var_name)
Contains Interface base classes and base types.
FilePath(const char *filename="")
Definition: AttributeTree.h:49
icl_core::String absoluteName() const
Definition: AttributeTree.h:77
const char * attribute() const
icl_core::String path() const
Definition: AttributeTree.h:63
void appendAttribute(const char *attribute, const char *separator="")
icl_core::String name() const
Definition: AttributeTree.h:70
bool Get(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToRef value) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:648
static icl_core::String exchangeSeparators(const icl_core::String &filename)
icl_core::String extension() const
Definition: AttributeTree.h:92
icl_core::String absolutePath(const icl_core::String &filename) const
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58