# # patch "ChangeLog" # from [b9f8dc67eb052de09b945006babfa6821b7ab659] # to [ad0bc4053096c5fdad73b9b6fed9ab342c5bf84b] # # patch "vocab.cc" # from [fb4266f80d864d01b7e2449060df50c29d55b2c5] # to [da6bdb0081213dee3f0268846d7b0cacedc68b35] # # patch "vocab.hh" # from [8748cf40dd076dd813dbdab8d722b6da167218f0] # to [9aa50b972ad3671eb3b0af85fec6227ff21f165e] # # patch "vocab_terms.hh" # from [e1637d600ff20487c2c87a9f46a5291a49c09b50] # to [2ac7518f6c9951c9335409298b21fcbe8ad76e27] # --- ChangeLog +++ ChangeLog @@ -1,5 +1,12 @@ 2005-04-22 Nathaniel Smith + * vocab.{cc,hh}: Make verify functions public, make ATOMIC(foo)'s + verify function a friend of foo, add ATOMIC_NOVERIFY macro, add + long comment explaining all this. + * vocab_terms.hh: Add _NOVERIFY to some types. + +2005-04-22 Nathaniel Smith + * file_io.{cc,hh} (localized): Take file_path/local_path instead of string; expose in public interface. Adjust rest of file to match. --- vocab.cc +++ vocab.cc @@ -18,12 +18,33 @@ using namespace std; +// the verify() stuff gets a little complicated; there doesn't seem to be a +// really nice way to achieve what we want with c++'s type system. the +// problem is this: we want to give verify(file_path) and verify(local_path) +// access to the internals of file_path and local_path, i.e. make them +// friends, so they can normalize the file paths they're given. this means +// that verify() needs to be declared publically, so that the definition of +// these classes can refer to them. it also means that they -- and all other +// ATOMIC types -- cannot fall back on a templated version of verify if no +// other version is defined, because, well, the friend thing and the template +// thing just don't work out, as far as I can tell. So, every ATOMIC type +// needs an explicitly defined verify() function, so we have both ATOMIC() and +// ATOMIC_NOVERIFY() macros, the latter of which defines a type-specific noop +// verify function. DECORATE and ENCODING, on the other hand, cannot make use +// of a trick like these, because they are template types themselves, and we +// want to be able to define verify(hexenc) without defining +// verify(hexenc) at the same time, for instance. Fortunately, these +// types never need to be friends with their verify functions (yet...), so we +// _can_ use a templated fallback function. This templated function is used +// _only_ by DECORATE and ENCODING; it would be nice to make it take an +// argument of type T1 to document that, but for some reason that doesn't +// work either. template static inline void verify(T & val) {} -static inline void +inline void verify(hexenc & val) { if (val.ok) @@ -41,7 +62,7 @@ val.ok = true; } -static inline void +inline void verify(ace & val) { if (val.ok) @@ -55,7 +76,7 @@ } -static inline void +inline void verify(cert_name & val) { if (val.ok) @@ -68,7 +89,7 @@ val.ok = true; } -static inline void +inline void verify(rsa_keypair_id & val) { if (val.ok) @@ -82,7 +103,7 @@ } -static inline void +inline void verify(local_path & val) { @@ -94,9 +115,7 @@ try { p = mkpath(val()); -#if BOOST_VERSION >= 103100 p = p.normalize(); -#endif } catch (std::runtime_error &re) { @@ -133,7 +152,7 @@ val.ok = true; } -static inline void +inline void verify(file_path & val) { static std::set known_good; @@ -174,6 +193,7 @@ ty const & a) \ { return (o << a.s); } +#define ATOMIC_NOVERIFY(ty) ATOMIC(ty) --- vocab.hh +++ vocab.hh @@ -91,11 +91,15 @@ ty const & operator=(ty const & other); \ bool operator==(ty const & other) const \ { return s == other(); } \ + friend void verify(ty &); \ friend std::ostream & operator<<(std::ostream &, \ ty const &); \ }; \ std::ostream & operator<<(std::ostream &, ty const &); +#define ATOMIC_NOVERIFY(ty) \ +ATOMIC(ty) \ +inline void verify(ty &) {} #define EXTERN extern @@ -103,6 +107,7 @@ #undef EXTERN #undef ATOMIC +#undef ATOMIC_NOVERIFY #undef DECORATE #undef ENCODING --- vocab_terms.hh +++ vocab_terms.hh @@ -7,33 +7,33 @@ // in order to facilitate external instantiation of most of the // vocabulary, minimize code duplication, speed up compilation, etc. -ATOMIC(external); // "external" string in unknown system charset -ATOMIC(utf8); // unknown string in UTF8 charset +ATOMIC_NOVERIFY(external); // "external" string in unknown system charset +ATOMIC_NOVERIFY(utf8); // unknown string in UTF8 charset ATOMIC(ace); // unknown string in ACE form -ATOMIC(id); // hash of data -ATOMIC(data); // meaningless blob -ATOMIC(delta); // xdelta between 2 datas -ATOMIC(inodeprint); // fingerprint of an inode +ATOMIC_NOVERIFY(id); // hash of data +ATOMIC_NOVERIFY(data); // meaningless blob +ATOMIC_NOVERIFY(delta); // xdelta between 2 datas +ATOMIC_NOVERIFY(inodeprint); // fingerprint of an inode ATOMIC(local_path); // non-absolute file ATOMIC(file_path); // non-absolute, non-bookeeping file ATOMIC(cert_name); // symbol-of-your-choosing -ATOMIC(cert_value); // symbol-of-your-choosing +ATOMIC_NOVERIFY(cert_value); // symbol-of-your-choosing // some domains: "database" (+ default_server, default_collection), // server_key (+ servername/key) // branch_alias (+ short form/long form) // trust_seed (+ branch/seed) -ATOMIC(var_domain); // symbol-of-your-choosing -ATOMIC(var_name); // symbol-of-your-choosing -ATOMIC(var_value); // symbol-of-your-choosing +ATOMIC_NOVERIFY(var_domain); // symbol-of-your-choosing +ATOMIC_NOVERIFY(var_name); // symbol-of-your-choosing +ATOMIC_NOVERIFY(var_value); // symbol-of-your-choosing -ATOMIC(rsa_keypair_id); // address@hidden -ATOMIC(rsa_pub_key); // some nice numbers -ATOMIC(rsa_priv_key); // some nice numbers -ATOMIC(rsa_sha1_signature); // some other nice numbers +ATOMIC(rsa_keypair_id); // address@hidden +ATOMIC_NOVERIFY(rsa_pub_key); // some nice numbers +ATOMIC_NOVERIFY(rsa_priv_key); // some nice numbers +ATOMIC_NOVERIFY(rsa_sha1_signature); // some other nice numbers DECORATE(revision); // thing associated with a revision DECORATE(manifest); // thing associated with a manifest @@ -45,8 +45,8 @@ ENCODING(base64); // thing which is base64-encoded ENCODING(arc4); // thing which is arc4-encrypted -ATOMIC(prefix); // raw encoding of a merkle tree prefix -ATOMIC(merkle); // raw encoding of a merkle tree node +ATOMIC_NOVERIFY(prefix); // raw encoding of a merkle tree prefix +ATOMIC_NOVERIFY(merkle); // raw encoding of a merkle tree node // instantiate those bits of the template vocabulary actually in use.