#ifndef INCLUDED_BOBCAT_GLOB_
#define INCLUDED_BOBCAT_GLOB_

#include <unordered_set>
#include <string>
#include <glob.h>

#include <bobcat/gs>

namespace FBB
{

class Glob: public GS__
{
    struct GlobShare;

    GlobShare *d_share;

    public:
        enum Flags
        {
            NO_FLAG = 0,    // to avoid having to use 0

            // These flags are equal to the ones used in <glob.h>

            ERR =       1 << 0, // Return on read errors.
            MARK =      1 << 1, // Append a slash to each name.
            NOSORT =    1 << 2, // Don't sort the names.
            NOESCAPE =  1 << 6, // Backslashes don't quote metacharacters.
            PERIOD =    1 << 7, // Leading `.' can be matched by metachars.

            NOMATCH =   1 << 8, // No matches are OK (size() returns 0)

            mask = (1 << 9) - 1 // all of the above flags
        };

        enum Dots
        {
            FIRST,
            DEFAULT
        };
            
        Glob(std::string const &pattern = "*", int flags = PERIOD,  // 1
             Dots dots = FIRST);
        Glob(Type type, std::string const &pattern = "*",           // 2
                int flags = PERIOD, Dots dots = FIRST);
        Glob(Glob &&tmp);                                           // 3
        Glob(Glob const &other);                                    // 4
        Glob(std::unordered_set<Type> const &type,                  // 5
                std::string const &pattern = "*",           
                int flags = PERIOD, Dots dots = FIRST);

        ~Glob();

        Glob &operator=(Glob const &other);
        Glob &operator=(Glob &&tmp);

        size_t size() const;
        char const *operator[](size_t idx) const;
        char const *const *begin() const;
        char const *const *end() const;

        void swap(Glob &other);

    private:
        char const **mbegin() const;                    // .f
        char const **mend() const;                      // .f

        void accept();

        static std::unordered_set<Type> fillSet(Type type);
        static bool isDot(char const *cp);
};

} // FBB
        
#endif




