*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / tool.cpp
CommitLineData
ea4c19a4 1#include <vector>
2#include <string>
3
4#include <stdio.h>
5
6#include "config.hh"
7
8using namespace std;
9
10/*!
11 *\brief Output a vector of strings to out_fd.
12 *\arg strings A vector containing text.
13 *\retval 0 The vector was empty.
14 *\retval 1 The vector contained text.
15 */
16int dump_vector(vector<string> strings){
17 int res=0;
18 for (vector<string>::iterator iter=strings.begin();iter<strings.end();iter++){
19 char buffer[50000];
20 snprintf(buffer,50000,"%s\n",(*iter).c_str());
21 write (out_fd,buffer,strlen(buffer));
22 res=1;
23 }
24 return res;
25}
26
27/*!
874a2bd8 28 *\brief Output a vector of strings.
ea4c19a4 29 *\arg strings A vector containing text.
874a2bd8 30 *\arg fp A FILE pointer where to write to.
ea4c19a4 31 *\retval 0 The vector was empty.
32 *\retval 1 The vector contained text.
33 */
874a2bd8 34int dump_vector_fp(vector<string> strings, FILE * fp){
ea4c19a4 35 int res=0;
36 for (vector<string>::iterator iter=strings.begin();iter<strings.end();iter++){
874a2bd8 37 fprintf(fp,"%s\n",(*iter).c_str());
ea4c19a4 38 res=1;
39 }
40 return res;
41}
874a2bd8 42
43/*!
44 *\brief add contents of one vector to another vector uniquely.
45 *\param target Reference to the target vector.
46 *\param source Reference to the vector whose contents are to be added
47 * to target.
48 */
49template<typename T>
50void merge_vector_unique(vector<T> &target, const vector<T> & source){
51 for (unsigned int isource=0; isource<source.size();isource++){
52 bool already_present=false;
53 for (int itarget=0;itarget<target.size();itarget++)
54 if (target[itarget]==source[isource]){
55 already_present=true;
56 break;
57 }
58 if (!already_present) target.insert(target.end().source[isource]);
59 }
60}