1 /*
2 
3   tag::write::ID3 applicative class
4 
5   copyright (c) 2004, 2005 squell <squell@alumina.nl>
6 
7   use, modification, copying and distribution of this software is permitted
8   under the conditions described in the file 'COPYING'.
9 
10   Usage:
11 
12   The write::ID3 class implements the interface for ID3 tags
13 
14   Example:
15 
16   int main(int argc, char* argv[])
17   {
18       tag::write::ID3()
19       .set(artist, "%2")
20       .set(title,  "%3")
21       .modify(argv[1], argv);
22   }
23 
24 */
25 
26 #ifndef __ZF_SETID3
27 #define __ZF_SETID3
28 
29 #include <string>
30 #include <utility>
31 #include "set_base.h"
32 
33 struct ID3v1;                                 // avoid a header dependency
34 
35 namespace tag {
36 
37     namespace write {
38 
39         class ID3 : public handler, public reader {
40         public:
41             bool      vmodify(const char*, const function&) const;
42             metadata* read(const char*) const;
43 
44           // standard set
ID3()45             ID3() : update(), cleared(), generate(), null_tag() { }
46            ~ID3();
47 
set(ID3field i,std::string m)48             ID3& set(ID3field i, std::string m)
49             { if(i < FIELD_MAX) update[i] = m; return *this; }
50 
51             ID3& rewrite(bool t = true)
52             { cleared = t;  return *this; }
53 
54             ID3& create(bool t = true)
55             { generate = t; return *this; }
56 
57           // extended
58             bool from(const char* fn);
59 
60         private:
61             struct nullable : private std::pair<std::string, bool> {
62                 struct null;
63                 void operator=(const null*)           { first.erase(), second = 0; }
64                 void operator=(std::string p)         { first.swap(p), second = 1; }
65                 operator const std::string*() const   { return second? &first : 0; }
66                 const std::string* operator->() const { return *this; }
67             };
68             nullable update[FIELD_MAX]; // modification data
69             bool cleared;               // should vmodify clear existing tag?
70             bool generate;              // don't *add* new tags to files?
71             const ID3v1* null_tag;      // use as base tag
72         };
73 
74     }
75 }
76 
77 #endif
78 
79