AttributeTree.h
Go to the documentation of this file.
00001 // this is a -*- C++ -*- file
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00027 //----------------------------------------------------------------------
00028 #ifndef ICL_CORE_CONFIG_ATTRIBUTE_TREE_H_INCLUDED
00029 #define ICL_CORE_CONFIG_ATTRIBUTE_TREE_H_INCLUDED
00030 
00031 #include <fstream>
00032 #include <string>
00033 
00034 #include "icl_core/BaseTypes.h"
00035 #include "icl_core_config/ImportExport.h"
00036 
00037 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00038 # include "icl_core/Deprecate.h"
00039 #endif
00040 
00041 namespace icl_core {
00042 namespace config {
00043 
00044 class AttributeTree;
00045 
00046 class FilePath
00047 {
00048 public:
00049   FilePath(const char *filename = "")
00050   {
00051     init(filename);
00052   }
00053   FilePath(const icl_core::String& filename)
00054   {
00055     init(filename.c_str());
00056   }
00057 
00058   ~FilePath()
00059   { }
00060 
00063   icl_core::String path() const
00064   {
00065     return icl_core::String(m_file, 0, m_file_path_name_split);
00066   }
00067 
00070   icl_core::String name() const
00071   {
00072     return icl_core::String(m_file, m_file_path_name_split, icl_core::String::npos);
00073   }
00074 
00077   icl_core::String absoluteName() const
00078   {
00079     return m_file;
00080   }
00081 
00085   icl_core::String currentDir() const
00086   {
00087     return m_pwd;
00088   }
00089 
00092   icl_core::String extension() const
00093   {
00094     return icl_core::String(m_file, m_file_name_extension_split, icl_core::String::npos);
00095   }
00096 
00100   icl_core::String absolutePath(const icl_core::String& filename) const;
00101 
00105   static bool isRelativePath(const icl_core::String& filename);
00106 
00109   bool isRelativePath() const
00110   {
00111     return FilePath::isRelativePath(m_file);
00112   }
00113 
00118   static icl_core::String normalizePath(const icl_core::String& filename);
00119 
00127   static icl_core::String exchangeSeparators(const icl_core::String& filename);
00128 
00131   static icl_core::String getEnvironment(const icl_core::String& var_name);
00132 
00137   static icl_core::String replaceEnvironment(const icl_core::String& filename);
00138 
00140 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00141 
00145   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String Path() const ICL_CORE_GCC_DEPRECATE_STYLE;
00149   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String Name() const ICL_CORE_GCC_DEPRECATE_STYLE;
00150 
00154   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String AbsoluteName() const ICL_CORE_GCC_DEPRECATE_STYLE;
00155 
00159   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String CurrentDir() const ICL_CORE_GCC_DEPRECATE_STYLE;
00160 
00164   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String Extension() const ICL_CORE_GCC_DEPRECATE_STYLE;
00165 
00169   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String AbsolutePath(const icl_core::String& filename) const
00170     ICL_CORE_GCC_DEPRECATE_STYLE;
00171 
00175   ICL_CORE_VC_DEPRECATE_STYLE static bool IsRelativePath(const icl_core::String& filename)
00176     ICL_CORE_GCC_DEPRECATE_STYLE;
00177 
00181   ICL_CORE_VC_DEPRECATE_STYLE bool IsRelativePath() const ICL_CORE_GCC_DEPRECATE_STYLE;
00182 
00186   ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String NormalizePath(const icl_core::String& filename)
00187     ICL_CORE_GCC_DEPRECATE_STYLE;
00188 
00194   ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String ExchangeSeparators(const icl_core::String& filename)
00195     ICL_CORE_GCC_DEPRECATE_STYLE;
00196 
00200   ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String GetEnvironment(const icl_core::String& var_name)
00201     ICL_CORE_GCC_DEPRECATE_STYLE;
00202 
00206   ICL_CORE_VC_DEPRECATE_STYLE static icl_core::String ReplaceEnvironment(const icl_core::String& filename)
00207     ICL_CORE_GCC_DEPRECATE_STYLE;
00208 
00209 #endif
00210 
00211 
00212 private:
00213   void init(const char *filename);
00214 
00215   icl_core::String m_pwd;
00216   icl_core::String m_file;
00217   icl_core::String::size_type m_file_path_name_split;
00218   icl_core::String::size_type m_file_name_extension_split;
00219 };
00220 
00221 
00225 class ICL_CORE_CONFIG_IMPORT_EXPORT SubTreeList
00226 {
00227   friend class AttributeTree;
00228 
00229 public:
00230   SubTreeList(AttributeTree *sub_tree = 0, SubTreeList *next = 0);
00231   ~SubTreeList();
00232   void copy(AttributeTree *parent);
00233   void unlinkParent();
00234   void unlink(AttributeTree *obsolete_tree);
00235   AttributeTree *subTree(const char *description);
00236   int contains();
00237   void printSubTree(std::ostream& out, int change_style_depth, char *upper_description);
00238   void printXmlSubTree(std::ostream& out, const std::string& upper_description);
00239   bool changed();
00240   AttributeTree *search(const char *description, const char *attribute);
00241   AttributeTree *next(AttributeTree *prev);
00242   void unmarkChanges();
00243 
00246   SubTreeList *revertOrder(SubTreeList *new_next = NULL);
00247 
00251   void newSubTreeList(AttributeTree *new_tree, AttributeTree *after);
00252 
00254 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00255 
00259   ICL_CORE_VC_DEPRECATE_STYLE SubTreeList *RevertOrder(SubTreeList *new_next = NULL)
00260     ICL_CORE_GCC_DEPRECATE_STYLE;
00261 
00266   ICL_CORE_VC_DEPRECATE_STYLE void NewSubTreeList(AttributeTree *new_tree, AttributeTree *after)
00267     ICL_CORE_GCC_DEPRECATE_STYLE;
00268 
00269 #endif
00270 
00271 
00272 private:
00273   // Forbid copying.
00274   SubTreeList(const SubTreeList&);
00275   SubTreeList& operator = (const SubTreeList&);
00276 
00277   SubTreeList *m_next;
00278   AttributeTree *m_sub_tree;
00279 };
00280 
00307 class ICL_CORE_CONFIG_IMPORT_EXPORT AttributeTree
00308 {
00309   friend class SubTreeList;
00310 
00311 public:
00314   enum
00315   {
00316     eOK,              
00317     eEMPTY_TREE,      
00318     eFILE_SAVE_ERROR, 
00319     eFILE_LOAD_ERROR  
00320   };
00323   AttributeTree(const char *description = 0, AttributeTree *parent = 0);
00324 
00328   AttributeTree(const AttributeTree& other);
00329 
00337   AttributeTree(const AttributeTree& other, AttributeTree *parent);
00338 
00342   ~AttributeTree();
00343 
00347   void unlink();
00348 
00352   void unlinkSub();
00353 
00358   // inline AttributeTree *getSubTree(const char *description)
00359   // { return getOrCreateSubTree()->setAttribute(description, 0); }
00360 
00367   AttributeTree *setAttribute(const char *description, const char *attribute);
00368 
00372   AttributeTree *setAttribute(const char *description, const char *subdescription, const char *attribute);
00373 
00378   // inline AttributeTree *setSubAttribute(const char *description, const char *attribute)
00379   // { return setAttribute(m_this_description, description, attribute); }
00380 
00383   char *getAttribute()
00384   {
00385     return m_this_attribute;
00386   }
00387 
00392   char *getAttribute(const char *description, const char *default_attribute = 0,
00393                      AttributeTree **subtree = 0);
00394 
00398   char *getOrSetDefault(const char *description, const char *default_attribute);
00399 
00403   int save(const char *filename, int change_style_depth = 3, bool unmark_changes = true);
00404 
00422   int load(const char *filename, bool unmark_changes = true, bool process_include = true,
00423            bool load_comments = false, bool preserve_order = false);
00424 
00427   int get(std::istream &in, bool process_include = true, bool load_comments = false,
00428           const FilePath *file_path = NULL);
00429 
00441   char *newSubNodeDescription(const char *base_description = "");
00442 
00445   AttributeTree *addNewSubTree();
00446 
00451   void printSubTree(std::ostream &out, int change_style_depth = 3, const char *upper_description = 0);
00452 
00455   const char *getDescription() const
00456   {
00457     return m_this_description;
00458   }
00459 
00462   const char *attribute() const
00463   {
00464     return m_this_attribute;
00465   }
00466 
00469   void setDescription(const char *description);
00470 
00473   void setAttribute(const char *attribute);
00474 
00477   void setComment(const char *comment);
00478 
00482   AttributeTree *subTree(const char *description);
00483 
00487   AttributeTree *getSubTree(const char *description);
00488 
00492   AttributeTree *firstSubTree()
00493   {
00494     if (m_subtree_list)
00495     {
00496       return m_subtree_list->m_sub_tree;
00497     }
00498     else
00499     {
00500       return NULL;
00501     }
00502   }
00503 
00507   AttributeTree *nextSubTree(AttributeTree *subtree)
00508   {
00509     if (m_subtree_list)
00510     {
00511       return m_subtree_list->next(subtree);
00512     }
00513     else
00514     {
00515       return NULL;
00516     }
00517   }
00518 
00522   AttributeTree *parentTree()
00523   {
00524     return m_parent;
00525   }
00526 
00532   AttributeTree *addSubTree(AttributeTree *subtree)
00533   {
00534     return addSubTree(subtree, NULL);
00535   }
00536 
00544   AttributeTree *addNextTree(AttributeTree *nexttree)
00545   {
00546     if (m_parent)
00547     {
00548       return m_parent->addSubTree(nexttree, this);
00549     }
00550     else
00551     {
00552       return NULL;
00553     }
00554   }
00555 
00562   AttributeTree *search(const char *description, const char *attribute);
00563 
00567   bool isAttribute(const char *description, const char *attribute = 0);
00568 
00572   bool changed();
00573 
00576   void unmarkChanges();
00577 
00580   int contains();
00581 
00584   AttributeTree *parent()
00585   {
00586     return m_parent;
00587   }
00588 
00591   AttributeTree *root()
00592   {
00593     AttributeTree *at = this;
00594     for (; at->m_parent; at = at->m_parent) {}
00595     return at;
00596   }
00597 
00601   const char *comment();
00602 
00605   bool hasComment()
00606   {
00607     return commentAttributeTree() != NULL;
00608   }
00609 
00612   bool isComment();
00613 
00616   bool hasMultilineComment();
00617 
00620   bool isMultilineComment();
00621 
00624   AttributeTree *commentAttributeTree();
00625 
00631   void appendAttribute(const char *attribute, const char *separator = "")
00632   {
00633     appendString(m_this_attribute, attribute, separator);
00634   }
00635 
00641   void appendDescription(const char *description, const char *separator = "")
00642   {
00643     appendString(m_this_description, description, separator);
00644   }
00645 
00648   void revertOrder()
00649   {
00650     if (m_subtree_list)
00651     {
00652       m_subtree_list = m_subtree_list->revertOrder();
00653     }
00654   }
00655 
00664   static const char *m_file_path_str;
00665 
00669   const char *getFilePath()
00670   {
00671     const char *ret = root()->getSpecialAttribute(m_file_path_str);
00672     if (!ret)
00673     {
00674       ret = "";
00675     }
00676     return ret;
00677   }
00678 
00687   static const char *m_file_name_str;
00688 
00693   const char *fileName()
00694   {
00695     const char *ret = root()->getSpecialAttribute(m_file_name_str);
00696     if (!ret)
00697     {
00698       ret = "";
00699     }
00700     return ret;
00701   }
00702 
00704 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00705 
00709   ICL_CORE_VC_DEPRECATE_STYLE void Unlink() ICL_CORE_GCC_DEPRECATE_STYLE;
00710 
00714   ICL_CORE_VC_DEPRECATE_STYLE void UnlinkSub() ICL_CORE_GCC_DEPRECATE_STYLE;
00715 
00719   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SetAttribute(const char *description,
00720                                                           const char *attribute)
00721     ICL_CORE_GCC_DEPRECATE_STYLE;
00722 
00727   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SetAttribute(const char *description,
00728                                                           const char *subdescription,
00729                                                           const char *attribute)
00730     ICL_CORE_GCC_DEPRECATE_STYLE;
00731 
00735   ICL_CORE_VC_DEPRECATE_STYLE char *GetAttribute() ICL_CORE_GCC_DEPRECATE_STYLE;
00736 
00740   ICL_CORE_VC_DEPRECATE_STYLE char *GetAttribute(const char *description,
00741                                                  const char *default_attribute = 0,
00742                                                  AttributeTree **subtree = 0)
00743     ICL_CORE_GCC_DEPRECATE_STYLE;
00744 
00748   ICL_CORE_VC_DEPRECATE_STYLE char *GetOrSetDefault(const char *description,
00749                                                     const char *default_attribute)
00750     ICL_CORE_GCC_DEPRECATE_STYLE;
00751 
00755   ICL_CORE_VC_DEPRECATE_STYLE int Save(const char *filename, int change_style_depth = 3,
00756                                        bool unmark_changes = true)
00757     ICL_CORE_GCC_DEPRECATE_STYLE;
00758 
00762   ICL_CORE_VC_DEPRECATE_STYLE int Load(const char *filename, bool unmark_changes = true,
00763                                        bool process_include = true,
00764                                        bool load_comments = false,
00765                                        bool preserve_order = false)
00766     ICL_CORE_GCC_DEPRECATE_STYLE;
00767 
00771   ICL_CORE_VC_DEPRECATE_STYLE int Get(std::istream &in, bool process_include = true,
00772                                       bool load_comments = false,
00773                                       const FilePath *file_path = NULL)
00774     ICL_CORE_GCC_DEPRECATE_STYLE;
00775 
00779   ICL_CORE_VC_DEPRECATE_STYLE char *NewSubNodeDescription(const char *base_description = "")
00780     ICL_CORE_GCC_DEPRECATE_STYLE;
00781 
00785   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *AddNewSubTree() ICL_CORE_GCC_DEPRECATE_STYLE;
00786 
00790   ICL_CORE_VC_DEPRECATE_STYLE void PrintSubTree(std::ostream &out,
00791                                                 int change_style_depth = 3,
00792                                                 const char *upper_description = 0)
00793     ICL_CORE_GCC_DEPRECATE_STYLE;
00794 
00798   ICL_CORE_VC_DEPRECATE_STYLE const char *Description() const ICL_CORE_GCC_DEPRECATE_STYLE;
00799 
00803   ICL_CORE_VC_DEPRECATE_STYLE const char *Attribute() const ICL_CORE_GCC_DEPRECATE_STYLE;
00804 
00808   ICL_CORE_VC_DEPRECATE_STYLE void SetDescription(const char *description)
00809     ICL_CORE_GCC_DEPRECATE_STYLE;
00810 
00814   ICL_CORE_VC_DEPRECATE_STYLE void SetAttribute(const char *attribute) ICL_CORE_GCC_DEPRECATE_STYLE;
00815 
00819   ICL_CORE_VC_DEPRECATE_STYLE void SetComment(const char *comment) ICL_CORE_GCC_DEPRECATE_STYLE;
00820 
00824   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *SubTree(const char *description)
00825     ICL_CORE_GCC_DEPRECATE_STYLE;
00826 
00830   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *GetSubTree(const char *description)
00831     ICL_CORE_GCC_DEPRECATE_STYLE;
00832 
00836   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *FirstSubTree() ICL_CORE_GCC_DEPRECATE_STYLE;
00837 
00841   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *NextSubTree(AttributeTree *subtree)
00842     ICL_CORE_GCC_DEPRECATE_STYLE;
00843 
00847   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *ParentTree() ICL_CORE_GCC_DEPRECATE_STYLE;
00848 
00852   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *AddSubTree(AttributeTree *subtree)
00853     ICL_CORE_GCC_DEPRECATE_STYLE;
00854 
00858   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *AddNextTree(AttributeTree *nexttree)
00859     ICL_CORE_GCC_DEPRECATE_STYLE;
00860 
00866   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *Search(const char *description, const char *attribute)
00867     ICL_CORE_GCC_DEPRECATE_STYLE;
00868 
00873   ICL_CORE_VC_DEPRECATE_STYLE bool IsAttribute(const char *description, const char *attribute = 0)
00874     ICL_CORE_GCC_DEPRECATE_STYLE;
00875 
00880   ICL_CORE_VC_DEPRECATE_STYLE bool Changed() ICL_CORE_GCC_DEPRECATE_STYLE;
00881 
00885   ICL_CORE_VC_DEPRECATE_STYLE void UnmarkChanges() ICL_CORE_GCC_DEPRECATE_STYLE;
00886 
00890   ICL_CORE_VC_DEPRECATE_STYLE int Contains() ICL_CORE_GCC_DEPRECATE_STYLE;
00891 
00895   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *Parent() ICL_CORE_GCC_DEPRECATE_STYLE;
00896 
00900   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *Root() ICL_CORE_GCC_DEPRECATE_STYLE;
00901 
00905   ICL_CORE_VC_DEPRECATE_STYLE const char *Comment() ICL_CORE_GCC_DEPRECATE_STYLE;
00906 
00910   ICL_CORE_VC_DEPRECATE_STYLE bool HasComment() ICL_CORE_GCC_DEPRECATE_STYLE;
00911 
00915   ICL_CORE_VC_DEPRECATE_STYLE bool IsComment() ICL_CORE_GCC_DEPRECATE_STYLE;
00916 
00920   ICL_CORE_VC_DEPRECATE_STYLE bool HasMultilineComment() ICL_CORE_GCC_DEPRECATE_STYLE;
00921 
00925   ICL_CORE_VC_DEPRECATE_STYLE bool IsMultilineComment() ICL_CORE_GCC_DEPRECATE_STYLE;
00926 
00930   ICL_CORE_VC_DEPRECATE_STYLE AttributeTree *CommentAttributeTree() ICL_CORE_GCC_DEPRECATE_STYLE;
00931 
00935   ICL_CORE_VC_DEPRECATE_STYLE void AppendAttribute(const char *attribute, const char *separator = "")
00936     ICL_CORE_GCC_DEPRECATE_STYLE;
00937 
00941   ICL_CORE_VC_DEPRECATE_STYLE void AppendDescription(const char *description, const char *separator = "")
00942     ICL_CORE_GCC_DEPRECATE_STYLE;
00943 
00947   ICL_CORE_VC_DEPRECATE_STYLE void RevertOrder() ICL_CORE_GCC_DEPRECATE_STYLE;
00948 
00953   ICL_CORE_VC_DEPRECATE_STYLE const char *GetFilePath() ICL_CORE_GCC_DEPRECATE_STYLE;
00954 
00959   ICL_CORE_VC_DEPRECATE_STYLE const char *FileName() ICL_CORE_GCC_DEPRECATE_STYLE;
00960 
00961 #endif
00962 
00963 
00964 
00965 private:
00966   void split(char *&description, char *&sub_description);
00967   void appendString(char * &dest, const char *src, const char *separator);
00968 
00969   // Forbid copying.
00970   AttributeTree& operator = (const AttributeTree&);
00971 
00974   char *getSpecialAttribute(const char *description, AttributeTree **subtree = NULL);
00975 
00978   AttributeTree *addSubTree(AttributeTree *subtree, AttributeTree *after_node);
00979 
00980   AttributeTree *m_parent;
00981   SubTreeList *m_subtree_list;
00982 
00983   char *m_this_description;
00984   char *m_this_attribute;
00985 
00986   bool m_changed;
00987 };
00988 
00989 }
00990 }
00991 
00992 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03