WModuleMetaInformation.h 6.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WMODULEMETAINFORMATION_H
#define WMODULEMETAINFORMATION_H

#include <string>
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
29
#include <vector>
30 31 32 33

#include <boost/shared_ptr.hpp>
#include <boost/filesystem/path.hpp>

34 35
#include "../common/WStructuredTextParser.h"

36
class WModule;
37 38 39

/**
 * A class abstracting module meta information. It encapsulates module name, description, icon, author lists, help resources, online resources
40 41
 * and much more. It is guaranteed to, at least, provide a module name. Everything else is optional. It also encapsulates the
 * WStructuredTextParser class for loading the data.
42 43 44 45 46 47 48 49 50 51 52 53 54 55
 */
class WModuleMetaInformation
{
public:
    /**
     * Convenience typedef for a boost::shared_ptr< WModuleMetaInformation >.
     */
    typedef boost::shared_ptr< WModuleMetaInformation > SPtr;

    /**
     * Convenience typedef for a boost::shared_ptr< const WModuleMetaInformation >.
     */
    typedef boost::shared_ptr< const WModuleMetaInformation > ConstSPtr;

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // these are some structs to simply handling of the meta file structures

    /**
     * Structure to contain all supported author information
     */
    struct Author
    {
        /**
         * Author name. Will never be empty.
         */
        std::string m_name;

        /**
         * URL to a website of the author. Can be empty.
         */
        std::string m_url;

        /**
         * E-Mail contact to the author. Can be empty.
         */
        std::string m_email;

        /**
         * What has this author done on the module? Can be empty.
         */
        std::string m_what;
    };

    /**
     * Structure to encapsulate the META info online resources.
     */
    struct Online
    {
        /**
         * Online resource's name.
         */
        std::string m_name;

        /**
         * Online resource's description.
         */
        std::string m_description;

        /**
         * The url to the resource.
         */
        std::string m_url;
    };

106
    /**
107 108
     * Constructor. The help object will be empty, meaning there is no further meta info available. The name is the only required value. Of
     * course, this is of limited use in most cases.
109 110 111 112 113 114
     *
     * \param name the name of the module
     */
    explicit WModuleMetaInformation( std::string name );

    /**
115
     * Construct a meta info object that loads all information from the specified file. If the file exist and could not be parsed, only
116
     * an error log is printed. No exception is thrown.
117
     *
118
     * \param module The module to load the meta file for.
119
     */
120
    explicit WModuleMetaInformation( boost::shared_ptr< WModule > module );
121 122 123 124 125

    /**
     * Destructor. Cleans internal list.
     */
    virtual ~WModuleMetaInformation();
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

    /**
     * The name of the module. Will always return the name of the module given on construction.
     *
     * \return the name
     */
    std::string getName() const;

    /**
     * Get the icon path. Can be invalid. Check for existence before opening.
     *
     * \return the path to the icon file
     */
    boost::filesystem::path getIcon() const;

    /**
     * The URL to a module website. Can be empty.
     *
     * \return URL to website
     */
    std::string getWebsite() const;

    /**
     * A module description. Can be empty but is initialized with the description of the module given on construction.
     *
     * \return the description.
     */
    std::string getDescription() const;

    /**
     * Path to a text or HTML file containing some module help. Can be invalid. Check for existence before opening.
     *
     * \return the path to help
     */
    boost::filesystem::path getHelp() const;

    /**
     * A list of authors. If the META file did not contain any author information, this returns the OpenWalnut Team as author.
     *
     * \return Author list.
     */
    std::vector< Author > getAuthors() const;

    /**
     * A list of online resources. Can be empty.
     *
     * \return list of online material
     */
    std::vector< Online > getOnlineResources() const;

176 177 178 179 180 181
    /**
     * A list of tags provided for the module.
     *
     * \return the tag list.
     */
    std::vector< std::string > getTags() const;
182 183 184 185 186 187
protected:
private:
    /**
     * The name of the module providing this meta information.
     */
    std::string m_name;
188

189 190 191 192 193 194
    /**
     * The default description if none was specified in the META file. Initialized with the description of the module specified during
     * construction.
     */
    std::string m_description;

195 196 197
    /**
     * The tree representing the data
     */
198
    WStructuredTextParser::StructuredValueTree m_metaData;
199 200 201 202 203 204

    /**
     * If true, m_metaData should be queried in all getters. If false, you can query m_meta but it will only tell you that the desired value
     * could not be found.
     */
    bool m_loaded;
205 206 207 208 209

    /**
     * The module local path. Used for several meta infos returning a path.
     */
    boost::filesystem::path m_localPath;
210 211 212 213
};

#endif  // WMODULEMETAINFORMATION_H