MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
ot_chaine.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// ot_chaine.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:53:59 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 #include "ot_chaine.h"
23 #include <string.h>
24 #include <stdlib.h>
25 #include <string>
26 #include <iostream>
27 #include <stdio.h>
28 #include <math.h>
29 #include <locale>
30 
31 
32 
33 
34 
36 {
37 transpose[0]='0';
38 transpose[1]='1';
39 transpose[2]='2';
40 transpose[3]='3';
41 transpose[4]='4';
42 transpose[5]='5';
43 transpose[6]='6';
44 transpose[7]='7';
45 transpose[8]='8';
46 transpose[9]='9';
47 transpose[10]='A';
48 transpose[11]='B';
49 transpose[12]='C';
50 transpose[13]='D';
51 transpose[14]='E';
52 transpose[15]='F';
53 transpose[16]='G';
54 transpose[17]='H';
55 transpose[18]='I';
56 transpose[19]='J';
57 transpose[20]='K';
58 transpose[21]='L';
59 transpose[22]='M';
60 transpose[23]='N';
61 transpose[24]='O';
62 transpose[25]='P';
63 transpose[26]='Q';
64 transpose[27]='R';
65 transpose[28]='S';
66 transpose[29]='T';
67 transpose[30]='U';
68 transpose[31]='V';
69 transpose[32]='W';
70 transpose[33]='X';
71 transpose[34]='Y';
72 transpose[35]='Z';
73 digit['0']=0;
74 digit['1']=1;
75 digit['2']=2;
76 digit['3']=3;
77 digit['4']=4;
78 digit['5']=5;
79 digit['6']=6;
80 digit['7']=7;
81 digit['8']=8;
82 digit['9']=9;
83 digit['A']=10;
84 digit['B']=11;
85 digit['C']=12;
86 digit['D']=13;
87 digit['E']=14;
88 digit['F']=15;
89 digit['G']=16;
90 digit['H']=17;
91 digit['I']=18;
92 digit['J']=19;
93 digit['K']=20;
94 digit['L']=21;
95 digit['M']=22;
96 digit['N']=23;
97 digit['O']=24;
98 digit['P']=25;
99 digit['Q']=26;
100 digit['R']=27;
101 digit['S']=28;
102 digit['T']=29;
103 digit['U']=30;
104 digit['V']=31;
105 digit['W']=32;
106 digit['X']=33;
107 digit['Y']=34;
108 digit['Z']=35;
109 }
110 
111 
112 
113 
115 {
116 
117 }
118 
119 
120 
122 {
123 
124 }
125 
126 
127 
128 void OT_CHAINE::ini_mg_fprintf(int pos,char c)
129 {
130 longmax=pos;
132 }
133 
134 
135 void OT_CHAINE::mg_fprintf(FILE* in,char* message)
136 {
137 std::string chaine=message;
138 int lon=chaine.length();
139 while (lon>longmax)
140  {
141  int pos=chaine.rfind(charseparateur,longmax);
142  std::string chaine1=chaine.substr(0,pos);
143  chaine=chaine.substr(pos);
144  lon=chaine.length();
145  fprintf(in,"%s\n",chaine1.c_str());
146  }
147 fprintf(in,"%s",chaine.c_str());
148 
149 
150 }
151 
152 std::string OT_CHAINE::get_base(unsigned long val,int base)
153 {
154 std::string res="";
155 do
156 {
157  int reste=val%base;
158  val=val/base;
159  res=transpose[reste]+res;
160 }
161 while (val!=0);
162 return res;
163 }
164 
165 
166 
167 unsigned long OT_CHAINE::get_base(std::string val,int base)
168 {
169 unsigned long res=0;
170 int taille=val.size();
171 for (int i=taille-1;i>-1;i--)
172  res=res+digit[val[i]]*pow(base,taille-i-1);
173 
174 
175 return res;
176 }
177 
178 long unsigned int OT_CHAINE::atoi(std::string val, int base)
179 {
180 unsigned long res=0;
181 if (base==10) res=atol(val.c_str());
182 else res=get_base(val,base);
183 return res;
184 }
185 
186 
187 std::vector< std::string> OT_CHAINE::split(std::string chaine, char c)
188 {
189 std::vector<std::string> arg;
190 int pos;
191 do
192 {
193 pos=chaine.find(c);
194 std::string chaine1=chaine.substr(0,pos);
195 arg.push_back(chaine1);
196 if (pos!=std::string::npos)
197  chaine=chaine.substr(pos+1);
198 }
199 while (pos!=std::string::npos);
200 return arg;
201 }
202 
203 
204 std::string OT_CHAINE::upcase(std::string chaine)
205 {
206  std::locale loc;
207  for (std::string::size_type i=0; i<chaine.length(); ++i)
208  chaine[i]= std::toupper(chaine[i],loc);
209  return chaine;
210 
211 }
212 
OT_CHAINE::get_base
std::string get_base(unsigned long val, int base)
Definition: ot_chaine.cpp:152
OT_CHAINE::split
std::vector< std::string > split(std::string chaine, char c)
Definition: ot_chaine.cpp:187
OT_CHAINE::transpose
char transpose[36]
Definition: ot_chaine.h:48
OT_CHAINE::digit
std::map< char, int > digit
Definition: ot_chaine.h:49
OT_CHAINE
Definition: ot_chaine.h:29
OT_CHAINE::mg_fprintf
void mg_fprintf(FILE *in, char *message)
Definition: ot_chaine.cpp:135
OT_CHAINE::charseparateur
char charseparateur
Definition: ot_chaine.h:47
OT_CHAINE::OT_CHAINE
OT_CHAINE()
Definition: ot_chaine.cpp:35
OT_CHAINE::upcase
std::string upcase(std::string chaine)
Definition: ot_chaine.cpp:204
OT_CHAINE::~OT_CHAINE
~OT_CHAINE()
Definition: ot_chaine.cpp:121
OT_CHAINE::ini_mg_fprintf
void ini_mg_fprintf(int pos, char c)
Definition: ot_chaine.cpp:128
res
#define res(i, j)
ot_chaine.h
OT_CHAINE::atoi
unsigned long atoi(std::string val, int base)
Definition: ot_chaine.cpp:178
OT_CHAINE::longmax
int longmax
Definition: ot_chaine.h:46