- 1
- 2
- 3
- 4
- 5
- 6
- 7
template <class Type, unsigned long Dim> inline MStreamTextIn&
MStreamTextIn::operator >>(const MMVector<Type, Dim>& o_value)
{
for (unsigned long i = 0; i < Dim; i++)
GetBaseStream() >> i_value[i];
return *this;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+160
template <class Type, unsigned long Dim> inline MStreamTextIn&
MStreamTextIn::operator >>(const MMVector<Type, Dim>& o_value)
{
for (unsigned long i = 0; i < Dim; i++)
GetBaseStream() >> i_value[i];
return *this;
}
copy-paste & templates
o_vlaue == i_value it's magic
+154
unsigned int i; // be positive! :D
+147
GOVNOREGER© для govnokod.ru
http://slil.ru/31180342
+175
if(v.isArray)value->setText("Array");
else value->setText(v.value.value("value").value<QString>());
if(v.value.value("color",QColor()).value<QColor>()!=QColor())
{
value->setBackgroundColor(v.value.value("color").value<QColor>());
}
Value, value, value, value, value, value, value ...
+147
class TTestLib
{
public:
char* Name;
unsigned int TotalTime;
TTestLib(char* AName): TotalTime(0), Name(AName) {}
...
}
char* Name - убило.
+163
class AnotherDammLoggerClass {
public:
// ...
static inline char *strtime()
{
// method is twice as fast as strftime)
static const int ASCII_OFFSET=48;
static char buffer[32]="";
struct timeval tv;
struct tm *lt;
if ( 0 == gettimeofday(&tv,NULL) )
{
lt=localtime(&tv.tv_sec);
int i=0;
/* year */
buffer[i++]=(lt->tm_year%100/10)+ASCII_OFFSET;
buffer[i++]=(lt->tm_year%10)+ASCII_OFFSET;
/* month */
buffer[i++]=((lt->tm_mon+1)/10)+ASCII_OFFSET;
buffer[i++]=((lt->tm_mon+1)%10)+ASCII_OFFSET;
/* day */
buffer[i++]=(lt->tm_mday/10)+ASCII_OFFSET;
buffer[i++]=(lt->tm_mday%10)+ASCII_OFFSET;
/* separator */
buffer[i++]='.';
/* hours */
buffer[i++]=(lt->tm_hour/10)+ASCII_OFFSET;
buffer[i++]=(lt->tm_hour%10)+ASCII_OFFSET;
/* minutes */
buffer[i++]=(lt->tm_min/10)+ASCII_OFFSET;
buffer[i++]=(lt->tm_min%10)+ASCII_OFFSET;
/* seconds */
buffer[i++]=(lt->tm_sec/10)+ASCII_OFFSET;
buffer[i++]=(lt->tm_sec%10)+ASCII_OFFSET;
/* separator */
buffer[i++]='.';
/* microseconds */
buffer[i++]=(((tv.tv_usec)%1000000)/100000)+ASCII_OFFSET;
buffer[i++]=(((tv.tv_usec)%100000)/10000)+ASCII_OFFSET;
buffer[i++]=(((tv.tv_usec)%10000)/1000)+ASCII_OFFSET;
buffer[i++]=(((tv.tv_usec)%1000)/100)+ASCII_OFFSET;
buffer[i++]=(((tv.tv_usec)%100)/10)+ASCII_OFFSET;
buffer[i++]=(((tv.tv_usec)%10))+ASCII_OFFSET;
/* delimiter */
buffer[i++]=(char)0;
}
else
{
strcpy(buffer, "<no time>");
}
return buffer;
}
// ....
}
оптимизируем производительность. коммент "twice as fast as strftime" порадовал: вместо того что бы редундантные вызовы поубирать, давайте ручками перепишем. для пущей красоты сделано inline (и еще скапипазджено в три других места проекта).
потому что в логгере strftime() наверное жутко тормозил - например по сравненю с записью сообщений на диск.......
+166
#include <dir.h>//ДЛЯ ОПРЕДЕЛЕНИЯ mkdir(ИМЯ ПАПКИ)
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include <iostream.h>
int ndig(char x)
{if('0'<=x&&x<='9')return 0;else return 1;}
// СТРОКА ВЕДОМОСТИ ДЛЯ ОДНОГО СТУДЕНТА
struct stud
{char fio[122];int b[9],ns
static int nc
,nd;
void out(FILE*fo);stud(){fio[121]=0;}
stud(FILE*fi);
stud(stud&s){*this=s;}
}; //end of stud body
int stud::nc=44;
int stud::nd=5;
stud::stud(FILE *fi)
{fscanf(fi,"%i ",&ns); fgets(fio,nc,fi);
for(int j=1;j<=nd;++j)fscanf(fi,"%i",&b[j]);}
void stud::out(FILE*fo=stdout)
{fprintf(fo,"%3i ",ns);
fputs(fio,fo); for(int j=1;j<=nd;++j)
{if(b[j]>=0&&b[j]<6) fprintf(fo,"%3i",b[j]);
else fprintf(fo," ");}
fprintf(fo,"\n"); if ( fo==stdout) getch();
}//end of stud
//ВЕДОМОСТЬ ОДНОЙ ГРУППЫ
//("МАССИВ СТРОК" ДЛЯ ОТДЕЛЬНЫХ СТУДЕНТОВ)
struct grup{ stud**st;//"МАССИВ СТУДЕНТОВ"
FILE*fi;char title[3][122]//"ШАПКА" ВЕДОМОСТИ
,sf[77];
int ms;//ЧИСЛО СТУДЕНТОВ
void nw();//ПАМЯТЬ ДЛЯ СТУДЕНТОВ
void out(char*sf); void out(FILE*fo);
grup(grup&g);grup(int fms){ms=fms; nw();}
grup(char*sf); grup&operator=(const grup&g);
void deg();~grup(){deg();} grup(); };
//end of grup body
grup::grup(){ms=0;st=0;fi=0;
for(int j=0;j<3;++j)memset(title[j],0,122);}
void grup::nw()
{st=new stud*[ms+1];
if(!st){cout<<"\nst=0 grup::nw()\n";exit(1);}
for(int j=0;j<=ms;++j)
{st[j]=new stud;
if(!st){cout<<"\nst[j]=0\n";exit(1);}
}}
grup::grup(char*fsf)
{strcpy(sf,fsf); char s[77]="\n"; int j;
fi=fopen(sf,"rt");
if(!fi)
{cout<<"\n0)fi=0,sf="<<sf;getch();exit(1);}
ms=0; while(!feof(fi)){fgets(s,77,fi);++ms;}
ms-=3; fclose(fi); fi=fopen(sf,"rt");
if(!fi){cout<<"\nfi\n";exit(1);}
for(j=0;j<3;++j) fgets((title[j]),77,fi);
//ВВОД "СТУДЕНТОВ" ИЗ ФАЙЛА sf
nw();for(j=1;j<=ms;++j){stud stj(fi);*st[j]=stj;}
fclose(fi);
}
grup&grup::operator=(const grup&g)
{if(this==&g)return*this; int j; this->deg();
fi=g.fi; strcpy(sf,g.sf); ms=g.ms;
nw(); for(j=0;j<=ms;++j)*st[j]=*g.st[j];
for(j=0;j<3;++j)strcpy(title[j],g.title[j]);
return*this;
}
grup::grup(grup&g)
{for(int j=0;j<3;++j)strcpy(title[j],g.title[j]);
ms=g.ms; strcpy(sf,g.sf);
nw(); for(j=0;j<=ms;++j)*st[j]=*g.st[j];
}
void grup::deg()
{if(st) {for(int j=0;j<=ms;++j)
if(st[j]){delete st[j];st[j]=0;}delete[]st;st=0;}
}
void grup::out(FILE*fo=stdout)
{if(fo==stdout)cout<<'\n'; int j=0;
for(;j<3;j++) fputs(title[j],fo);
for(j=1;j<=ms;j++) st[j]->out(fo);
}
void grup::out(char*sf)
{FILE*fo=fopen(sf,"wt");
if(!fo){cout<<"\nfo=0\n";exit(1);}
out(fo); fclose(fo);
} //end of grup
Кусок кода с "базовыми классами" для курсовой работы в непоследнем университете Петербурга. Данные "классы" потом по заданию предлагается всячески расширять.
А потом жалуемся, что студенты ничего не умеют. А кто ж их учит?
+165
inline void bubbleSort3(int* data)
{
int temp;
if (data[0] > data[1])
{ temp = data[0]; data[0] = data[1]; data[1] = temp; }
if (data[1] > data[2])
{ temp = data[1]; data[1] = data[2]; data[2] = temp; }
if (data[0] > data[1])
{ temp = data[0]; data[0] = data[1]; data[1] = temp; }
};
Пример "не верной" сортировки. Найдено на просторах Интернета.
+173
NNLayer::~NNLayer()
{
// call Initialize(); makes sense if you think
Initialize();
}
Отсюда: http://www.codeproject.com/KB/library/NeuralNetRecognition.aspx
+164
//----------------------------------------------------------------------------
void TChimesMinigame::InventoryEndDrag(str aId)
{
TSceneObject * drag_object = getScene(1)->FindObject(aId);
if (!drag_object)
{
iInventory->CheckEndDrag(NULL);
return;
}
iInventory->CheckEndDrag(NULL);
}
//----------------------------------------------------------------------------