DotFile.h

Go to the documentation of this file.
00001 
00004 /*
00005  *  Copyright (c) 2006, Philip de Nier, BBC Research and Development
00006  *
00007  *  This software is provided 'as-is', without any express or implied warranty.
00008  *  In no event will the authors be held liable for any damages arising from
00009  *  the use of this software.
00010  *
00011  *  Permission is granted to anyone to use this software for any purpose,
00012  *  including commercial applications, and to alter it and redistribute it
00013  *  freely, subject to the following restrictions:
00014  *
00015  *    1. The origin of this software must not be misrepresented; you must
00016  *       not claim that you wrote the original software. If you use this
00017  *       software in a product, an acknowledgment in the product
00018  *       documentation would be appreciated but is not required.
00019  *  
00020  *    2. Altered source versions must be plainly marked as such, and must
00021  *       not be misrepresented as being the original software.
00022  *  
00023  *    3. This notice may not be removed or altered from any source
00024  *       distribution.
00025  */
00026 
00027 #ifndef __DOTFILE_H__
00028 #define __DOTFILE_H__
00029 
00030 #include <string>
00031 #include <vector>
00032 
00033 
00034 namespace dot
00035 {
00036 
00037 class DotAttribute;
00038 
00039 class DotFile
00040 {
00041 public:
00042     DotFile(const char* filename);
00043     ~DotFile(void);
00044     
00045     void startGraph(std::string id);
00046     void endGraph(void);
00047     
00048     void startDefaultAttributes(std::string elementName);
00049     void endDefaultAttributes(void);
00050     
00051     void startCluster(std::string id);
00052     void endCluster(void);
00053  
00054     void startNode(std::string id);
00055     void endNode(void);
00056     
00057     void startEdge(std::string fromId, std::string toId);
00058     void endEdge(void);
00059     // allocate space for writing an edge later using startEdge(position... 
00060     long allocateEdgeSpace(unsigned int size = 60);
00061     void startEdge(long position, std::string fromId, std::string toId);
00062 
00063     void writeAttribute(std::string id, std::string value);
00064     void writeAttribute(DotAttribute* attribute);
00065     void writeAttributes(std::vector<DotAttribute*>& attributes);
00066     
00067     
00068     std::string getNextNodeId(void);
00069     std::string getNextClusterId(void);
00070     
00071     
00072     void test(std::string filename);
00073     
00074 private:
00075     enum DotState
00076     {
00077         START,
00078         ELEMENT,
00079         DEFAULT_ATTR,
00080         NODE,
00081         EDGE,
00082         ATTRIBUTES,
00083         END
00084     };
00085     
00086     FILE*       _dotFile;
00087     DotState    _state;
00088     long        _nextNodeId;
00089     long        _nextClusterId;
00090 };
00091 
00092 
00093 class DotAttribute
00094 {
00095 public:
00096     DotAttribute(void);
00097     virtual ~DotAttribute(void);
00098     
00099     void setId(std::string id);
00100     void setValue(std::string value);
00101     std::string getId(void);
00102     virtual std::string getValue(void);
00103 
00104 protected:
00105     std::string _id;
00106     std::string _value;
00107 };
00108 
00109 
00110 class DotObjectAttribute : public DotAttribute
00111 {
00112 public:
00113     DotObjectAttribute(void);
00114     virtual ~DotObjectAttribute(void);
00115   
00116     virtual std::string getValue(void);
00117     
00118     void setMaxPropertySize(unsigned int maxPropertySize);
00119     void setMaxPropertyWidth(unsigned int maxPropertyWidth);
00120     void setObjectName(std::string name);
00121     void addProperty(std::string name, std::string value);
00122     void addPropertyDef(std::string name, std::string type);
00123     // returns the width in inches
00124     std::string getDisplayWidth(float fixedPitch = -1.0);
00125     void setFontSize(float fontSize);
00126     
00127 protected:
00128     void addPropertyValueOrDef(std::string name, std::string typeOrValue, bool isValue);
00129     std::string escapeString(std::string value);
00130     
00131     std::string                 _name;
00132     std::vector<std::string>    _properties;
00133     unsigned int                _maxPropertySize;
00134     unsigned int                _maxPropertyWidth;
00135     unsigned int                _len;
00136     float                       _fontSize;
00137 };
00138     
00139 
00140 };
00141 
00142 #endif

Generated on Mon Apr 2 15:20:53 2007 for MXFLib by  doxygen 1.5.1-p1