]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/articlenumber.cpp
Rework article numbers
[r2c2.git] / source / libr2c2 / articlenumber.cpp
1 #include <msp/strings/utils.h>
2 #include "articlenumber.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 namespace R2C2 {
8
9 ArticleNumber::ArticleNumber(const string &a):
10         article(a)
11 { }
12
13 ArticleNumber::ArticleNumber(const string &v, const string &a, const string &p):
14         vendor(v),
15         article(a),
16         part(p)
17 { }
18
19 string ArticleNumber::str() const
20 {
21         string result;
22         if(!vendor.empty())
23         {
24                 result += vendor;
25                 result += ' ';
26         }
27         result += article;
28         if(!part.empty())
29         {
30                 result += '-';
31                 result += part;
32         }
33
34         return result;
35 }
36
37
38 ArticleNumber::Loader::Loader(ArticleNumber &an):
39         DataFile::ObjectLoader<ArticleNumber>(an)
40 {
41         add("vendor", &ArticleNumber::vendor);
42         add("article", &ArticleNumber::article);
43         add("part", &ArticleNumber::part);
44 }
45
46
47 void operator<<(LexicalConverter &conv, const ArticleNumber &art_nr)
48 {
49         conv.result(art_nr.str());
50 }
51
52 } // namespace R2C2