Vuo  2.3.2
VuoCompositionMetadata.cc
Go to the documentation of this file.
1 
11 #include "VuoStringUtilities.hh"
12 
17 {
18  defaultName = "VuoComposition";
19 }
20 
24 VuoCompositionMetadata::VuoCompositionMetadata(const string &compositionAsString)
25 {
26  defaultName = "VuoComposition";
27 
28  __block int charNum = 0;
29  string (^getNextLine)(void) = ^{
30  string line;
31  while (true)
32  {
33  char c = compositionAsString[charNum++];
34  if (c == '\n')
35  break;
36  if (c == 0)
37  return (string)"";
38  line += c;
39  }
40  return line;
41  };
42 
43  __block bool firstLine = true;
44  bool (^getNextDoxygenLine)(string &line) = ^(string &line){
45  while ((line = getNextLine()) != "")
46  {
47  if (firstLine)
48  {
49  firstLine = false;
50  if (line != "/**")
51  return false;
52  else
53  continue;
54  }
55 
56  if ((line == " */") || (line == "*/"))
57  return false;
58 
59  if (line.substr(0, 1) == "*")
60  {
61  if (line.length() > 1)
62  line = line.substr(2);
63  else
64  line = "";
65  return true;
66  }
67  if (line.substr(0, 2) == " *")
68  {
69  if (line.length() > 2)
70  line = line.substr(3);
71  else
72  line = "";
73  return true;
74  }
75  return false;
76  }
77  return false;
78  };
79 
80  string line;
81  bool firstDescriptionLine = true;
82  bool inCopyright = false;
83  bool inLicense = false;
84  while (getNextDoxygenLine(line))
85  {
86  if (line == "@file")
87  continue;
88 
89  if (line.substr(0, 7) == "@brief ")
90  {
91  name = line.substr(7);
92  continue;
93  }
94 
95  if (line.substr(0, 8) == "@author ")
96  {
97  author = line.substr(8);
98  continue;
99  }
100 
101  if (line.substr(0, 9) == "@version ")
102  {
103  version = line.substr(9);
104  continue;
105  }
106 
107  if (line.substr(0, 21) == "@createdInVuoVersion ")
108  {
109  createdInVuoVersion = line.substr(21);
110  continue;
111  }
112 
113  if (line.substr(0, 23) == "@lastSavedInVuoVersion ")
114  {
115  lastSavedInVuoVersion = line.substr(23);
116  continue;
117  }
118 
119  if (line.substr(0, 10) == "@keywords ")
120  {
121  string keywordsAsString = line.substr(10);
122  keywords = VuoStringUtilities::split(keywordsAsString, ',');
123  for (string &k : keywords)
125  continue;
126  }
127 
128  if (line.substr(0, 11) == "@copyright ")
129  {
130  inCopyright = true;
131  copyright = line.substr(11);
132  continue;
133  }
134 
135  if (line.substr(0, 9) == "@license ")
136  {
137  inCopyright = false;
138  inLicense = true;
139  license = line.substr(9);
140  continue;
141  }
142 
143  if (line == "")
144  {
145  inCopyright = false;
146  inLicense = false;
147  }
148 
149  if (line.substr(0, 12) == "@image icon ")
150  {
151  inCopyright = false;
152  inLicense = false;
153  iconURL = line.substr(12);
154  continue;
155  }
156 
157  if (line.substr(0, 14) == "@url homepage ")
158  {
159  inCopyright = false;
160  inLicense = false;
161  homepageURL = line.substr(14);
162  continue;
163  }
164 
165  if (line.substr(0, 19) == "@url documentation ")
166  {
167  inCopyright = false;
168  inLicense = false;
169  documentationURL = line.substr(19);
170  continue;
171  }
172 
173  if (line.substr(0, 8) == "@bundle ")
174  {
175  inCopyright = false;
176  inLicense = false;
177  bundleID = line.substr(8);
178  continue;
179  }
180 
181  if (line.substr(0, 13) == "@fxpluggroup ")
182  {
183  inCopyright = false;
184  inLicense = false;
185  fxPlugGroup = line.substr(13);
186  continue;
187  }
188 
189  if (line.substr(0, 5) == "@see ")
190  {
191  inCopyright = false;
192  inLicense = false;
193  continue;
194  }
195 
196  if (inCopyright)
197  {
198  copyright += '\n';
199  copyright += line;
200  continue;
201  }
202 
203  if (inLicense)
204  {
205  license += '\n';
206  license += line;
207  continue;
208  }
209 
210  if (!firstDescriptionLine)
211  description += '\n';
212  description += line;
213  firstDescriptionLine = false;
214  }
215 
216  // Trim leading and trailing newlines, if any.
217  while (description.size() > 0 && description[0] == '\n')
218  description.erase(description.begin());
219  while (description.size() > 0 && description[description.size()-1] == '\n')
220  description.erase(description.end() - 1);
221 }
222 
227 {
228  string metadataText =
229  "/**\n"
230  " * @file\n";
231 
232  if (! name.empty())
233  {
234  metadataText += " * @brief ";
235  metadataText += name;
236  metadataText += "\n";
237  }
238 
239  if (!description.empty())
240  {
241  vector<string> descriptionLines = VuoStringUtilities::split(description, '\n');
242  for (const string &descriptionLine : descriptionLines)
243  {
244  metadataText += " *";
245  metadataText += (descriptionLine.empty() ? "" : " ");
246  metadataText += descriptionLine;
247  metadataText += "\n";
248  }
249  }
250 
251  metadataText += " *\n";
252 
253  if (!author.empty())
254  {
255  metadataText += " * @author ";
256  metadataText += author;
257  metadataText += "\n";
258  }
259 
260  if (!version.empty())
261  {
262  metadataText += " * @version ";
263  metadataText += version;
264  metadataText += "\n";
265  }
266 
267  if (!createdInVuoVersion.empty())
268  {
269  metadataText += " * @createdInVuoVersion ";
270  metadataText += createdInVuoVersion;
271  metadataText += "\n";
272  }
273 
274  if (!lastSavedInVuoVersion.empty())
275  {
276  metadataText += " * @lastSavedInVuoVersion ";
277  metadataText += lastSavedInVuoVersion;
278  metadataText += "\n";
279  }
280 
281  if (!keywords.empty())
282  {
283  metadataText += " * @keywords ";
284  metadataText += VuoStringUtilities::join(keywords, ", ");
285  metadataText += "\n";
286  }
287 
288  if (!VuoStringUtilities::trim(copyright).empty())
289  {
290  metadataText += " * @copyright ";
291 
292  vector<string> copyrightLines = VuoStringUtilities::split(copyright, '\n');
293  bool firstCopyrightLine = true;
294  for (const string &copyrightLine : copyrightLines)
295  {
296  if (!copyrightLine.empty())
297  {
298  if (!firstCopyrightLine)
299  metadataText += " * ";
300  metadataText += copyrightLine;
301  metadataText += "\n";
302  firstCopyrightLine = false;
303  }
304  }
305  }
306 
307  if (!VuoStringUtilities::trim(license).empty())
308  {
309  metadataText += " * @license ";
310 
311  vector<string> licenseLines = VuoStringUtilities::split(license, '\n');
312  bool firstLicenseLine = true;
313  for (const string &licenseLine : licenseLines)
314  {
315  if (!licenseLine.empty())
316  {
317  if (!firstLicenseLine)
318  metadataText += " * ";
319  metadataText += licenseLine;
320  metadataText += "\n";
321  firstLicenseLine = false;
322  }
323  }
324  }
325 
326  if (!iconURL.empty())
327  {
328  metadataText += " * @image icon ";
329  metadataText += iconURL;
330  metadataText += "\n";
331  }
332 
333  if (!homepageURL.empty())
334  {
335  metadataText += " * @url homepage ";
336  metadataText += homepageURL;
337  metadataText += "\n";
338  }
339 
340  if (!documentationURL.empty())
341  {
342  metadataText += " * @url documentation ";
343  metadataText += documentationURL;
344  metadataText += "\n";
345  }
346 
347  if (!bundleID.empty())
348  {
349  metadataText += " * @bundle ";
350  metadataText += bundleID;
351  metadataText += "\n";
352  }
353 
354  if (!fxPlugGroup.empty())
355  {
356  metadataText += " * @fxpluggroup ";
357  metadataText += fxPlugGroup;
358  metadataText += "\n";
359  }
360 
361  metadataText +=
362  " * @see This is a Vuo Composition source code file. See https://vuo.org for further information.\n"
363  " */\n\n";
364 
365  return metadataText;
366 }
367 
372 {
373  this->name = name;
374 }
375 
379 void VuoCompositionMetadata::setDefaultName(const string &defaultName)
380 {
381  this->defaultName = defaultName;
382 }
383 
388 {
389  return name.empty() ? defaultName : name;
390 }
391 
396 {
397  return name;
398 }
399 
404 {
405  return defaultName;
406 }
407 
412 {
413  this->author = author;
414 }
415 
420 {
421  return author;
422 }
423 
428 {
429  this->description = description;
430 }
431 
436 {
437  return description;
438 }
439 
443 void VuoCompositionMetadata::setKeywords(const vector<string> &keywords)
444 {
445  this->keywords = keywords;
446 }
447 
452 {
453  return keywords;
454 }
455 
460 {
461  this->copyright = copyright;
462 }
463 
468 {
469  return copyright;
470 }
471 
476 {
477  this->license = license;
478 }
479 
484 {
485  return license;
486 }
487 
492 {
493  this->version = version;
494 }
495 
500 {
501  return version;
502 }
503 
508 {
509  this->createdInVuoVersion = version;
510 }
511 
516 {
517  return createdInVuoVersion;
518 }
519 
524 {
525  this->lastSavedInVuoVersion = version;
526 }
527 
532 {
533  return lastSavedInVuoVersion;
534 }
535 
540 {
541  this->iconURL = url;
542 }
543 
548 {
549  return iconURL;
550 }
551 
556 {
557  this->homepageURL = url;
558 }
559 
564 {
565  return homepageURL;
566 }
567 
572 {
573  this->documentationURL = url;
574 }
575 
580 {
581  return documentationURL;
582 }
583 
588 {
589  this->bundleID = id;
590 }
591 
596 {
597  return bundleID;
598 }
599 
604 {
605  this->fxPlugGroup = group;
606 }
607 
612 {
613  return fxPlugGroup;
614 }
615 
619 void VuoCompositionMetadata::setCategories(const vector<string> &categories)
620 {
621  this->categories = categories;
622 }
623 
628 {
629  return categories;
630 }