Boost logo

Boost :

From: Jan Langer (jan_at_[hidden])
Date: 2002-10-27 19:36:44


hello
i finally had time to try a better implementation of an filesystem
attribute system. it now can be applied as follows:

cache c (path_name);
assert (c.get_path () == get <filename> (c));
size::value_type i = get <size> (c);
put <owner> (c, "nobody");
commit <owner> (c); // now it is on definitly changed

if commit is not called then it is done on c's destruction.
i implemented size, filename, owner and group for posix to demonstrate
the usage.
the cache itself is nearly a property map according to the one at boost.
but there is no key, the key is the template parameter. it is
implemented by means of a map<type_info, value>.
i need a type_info wrapper as a key for the map. this is exactly what
the TypeInfo class of Loki does. so i just plainly included it as a
header. maybe it can be boostified, because andrei alexandrescu wanted
it in either way.
certain names i chose are not the best choice. so i'm open for any
better suggestions.

the attribute objects itself are stored in the cache and can be accessed
as follows:
      size &s = c.at <size> ();
but i am still not really sure what should be allowed to be done with
this object.

it is very simple to define user defined attributes and use the same
cache. for example:

      class test_attr
              : public fs::attribute <true, int,
                          fs::read_write_tag>
      {
          public:
              test_attr (fs::cache &pm)
                      : base_type (pm), v_ (17)
              {}

              value_type do_get ()
              {
                  return v_;
              }
              void do_put (value_type v)
              {
                  v_ = v;
              }
              void do_commit ()
              {
                  std::string p = get_cache () // get_cache is inherited
                                   .get_path ()
                                   .generic_path ();
                  std::cout << "commit: " << v_
                            << "; file: " << p << '\n';
              }

          private:
              value_type v_;
      };

and it can be used exactly like the builtin-attributes.

i put the implementation in an archive on my homepage
(http://www.langernetz.de/attributes.tar.gz). if you think that this
could be a reasonable approach then i can commit it into the sandbox,
after asking jeremy siek for the right to do so.
regards,
jan

-- 
jan langer ... jan_at_[hidden]
"pi ist genau drei"

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk