linux c++自己使用pthread封装的线程类
#include<iostream>
#include<pthread.h>
#include<unistd.h> using namespace std; //typedef void *(*methodFunction)(void *); class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
void wait();
private:
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
}; CThread::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(),
m_count()
{
} CThread::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = ;
} void CThread::run()
{
m_state = pthread_create(&m_thread, NULL, m_WorkFunction,m_args);
} void CThread::wait()
{
if( == m_state)
{
pthread_join(m_thread, NULL);
}
} int CThread::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction; return ;
} void * thread_work(void*)
{
for ( int i = ; i < ; i++)
{
cout << "the thread output the number:"<<i<< endl;
}
} int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread T;
T.setWorkMethod(thread_work);
T.run();
T.wait();
cout << "the process ending"<< endl;
return ;
}
//demo2: 传入相应参数
#include<iostream>
#include<pthread.h>
#include<unistd.h> using namespace std; //typedef void *(*methodFunction)(void *); class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
void wait();
private:
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
}; CThread::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(),
m_count()
{
} CThread::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = ;
} void CThread::run()
{
m_state = pthread_create(&m_thread, NULL, m_WorkFunction,m_args);
} void CThread::wait()
{
if( == m_state)
{
pthread_join(m_thread, NULL);
}
} int CThread::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction; return ;
} void * thread_work(void* args)
{
for ( int i = ; i < ; i++)
{
cout << "the thread output the number:"<<i<< (char*) args<<endl;
}
} int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread T;
T.setWorkMethod(thread_work, (void *)"hellowrold");
T.run();
T.wait();
cout << "the process ending"<< endl;
return ;
}
//demo3:抛出发送信息
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<string> using namespace std;
struct MSG
{
MSG():
_msg_count(),
_msg_str_message("")
{}
int _msg_count;
std::string _msg_str_message;
};
//typedef void *(*methodFunction)(void *); class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
int setSleepTimeForSeconds(int sec);
void sendMessage(void *(*dealMessageFunction)(MSG *), void* type = NULL);
void stop();
void wait();
private:
static void * func_workFunction(void * args);
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
bool m_destroy;
int m_sleepSeconds;
MSG m_msg;
}; CThread::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(),
m_count(),
m_sleepSeconds(),
m_destroy(false)
{
m_msg._msg_count = ;
m_msg._msg_str_message ="this is a message";
} CThread::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = ;
} void CThread::run()
{
m_state = pthread_create(&m_thread, NULL, func_workFunction, this);
} void CThread::wait()
{
if( == m_state)
{
pthread_join(m_thread, NULL);
}
}
void * CThread::func_workFunction(void * args)
{
CThread * ptrCThread = (CThread *)args;
while(NULL == ptrCThread->m_WorkFunction && !ptrCThread->m_destroy)
{
cout << "the thread do nothing, sleep "<< ptrCThread->m_sleepSeconds<<" seconds" << endl;
sleep(ptrCThread->m_sleepSeconds);
}
if(NULL != ptrCThread->m_WorkFunction && !ptrCThread->m_destroy)
{
//cout << "DEBUG:run the function "<< endl;
ptrCThread->m_WorkFunction(ptrCThread->m_args);
//cout << "DEBUG:end the function "<< endl;
}
} int CThread::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction;
//cout << "DEBUG:set method "<< endl;
return ;
}
void CThread::sendMessage(void *(*dealMessageFunction)(MSG *), void* type)
{
if(!m_msg._msg_str_message.empty())
{
if(NULL == type)
{
dealMessageFunction(&m_msg);
}else
{ }
}
} int CThread::setSleepTimeForSeconds(int sec)
{
if(sec > )
{
m_sleepSeconds = sec;
}
}
void CThread::stop()
{
m_destroy = true;
} void * thread_work(void* args)
{
for ( int i = ; i < ; i++)
{
cout << "the thread output the number: "<< i <<" "<< (char*) args<<endl;
}
} void * dealwithMessage(MSG * msg)
{
MSG tmpMsg;
tmpMsg._msg_count = msg->_msg_count;
tmpMsg._msg_str_message = msg->_msg_str_message; cout << "[INFO]***get the message from the thread***:"<< tmpMsg._msg_str_message << endl;
} void * tread_work1(void *args)
{
for( int i = ; i< ; i++)
{
cout <<"another tread output: "<< i <<" "<<(char*) args<< std::endl;
}
} int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread T;CThread T1;
//T.setWorkMethod(thread_work, (void *)"hellowrold");
T.run();
T1.run();T1.setWorkMethod(tread_work1, (void*)"wssdsfsafa");
T1.sendMessage(dealwithMessage);
sleep();
T.setWorkMethod(thread_work, (void *)"hellowrold");
T.wait();
T1.wait();
cout << "the process ending"<< endl;
return ;
}
//demo4: 线程调用类方法执行
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<string> using namespace std;
struct MSG
{
MSG():
_msg_count(0),
_msg_str_message("")
{}
int _msg_count;
std::string _msg_str_message;
};
//typedef void *(*methodFunction)(void *);
class CWork
{
public:
CWork();
~CWork();
void init(void *);
};
class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
int setWorkMethod(CWork & t, void * args = NULL);
// int setWorkMethod(const T *t, void * args = NULL);
int setSleepTimeForSeconds(int sec);
void sendMessage(void *(*dealMessageFunction)(MSG *), void* type = NULL);
void stop();
void wait();
private:
static void * func_workFunction(void * args);
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
bool m_destroy;
int m_sleepSeconds;
CWork *ptrCWork;
MSG m_msg;
}; CThread::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(0),
m_count(0),
m_sleepSeconds(2),
m_destroy(false),
ptrCWork(NULL)
{
m_msg._msg_count = 1;
m_msg._msg_str_message ="this is a message";
} CThread::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = 0;
} void CThread::run()
{
m_state = pthread_create(&m_thread, NULL, func_workFunction, this);
} void CThread::wait()
{
if( 0 == m_state)
{
pthread_join(m_thread, NULL);
}
}
void * CThread::func_workFunction(void * args)
{
CThread * ptrCThread = (CThread *)args;
while(NULL == ptrCThread->m_WorkFunction && !ptrCThread->m_destroy && ptrCThread->ptrCWork == NULL)
{
cout << "the thread do nothing, sleep "<< ptrCThread->m_sleepSeconds<<" seconds" << endl;
sleep(ptrCThread->m_sleepSeconds);
}
if(NULL != ptrCThread->m_WorkFunction && !ptrCThread->m_destroy)
{
//cout << "DEBUG:run the function "<< endl;
ptrCThread->m_WorkFunction(ptrCThread->m_args);
//cout << "DEBUG:end the function "<< endl;
}else if(NULL !=ptrCThread->ptrCWork && !ptrCThread->m_destroy)
{
ptrCThread->ptrCWork->init(ptrCThread->m_args);
}
} int CThread::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction;
//cout << "DEBUG:set method "<< endl;
return 0;
}
int CThread::setWorkMethod( CWork & t, void * args)
{
if(args != NULL)
{
m_args = args;
}
ptrCWork = &t;
}
// int CThread::setWorkMethod(const T *t, void * args)
// {
// T * ptrClass = (T*)t;
// ptrClass->init(args);
// }
void CThread::sendMessage(void *(*dealMessageFunction)(MSG *), void* type)
{
if(!m_msg._msg_str_message.empty())
{
if(NULL == type)
{
dealMessageFunction(&m_msg);
}else
{ }
}
} int CThread::setSleepTimeForSeconds(int sec)
{
if(sec > 0)
{
m_sleepSeconds = sec;
}
}
void CThread::stop()
{
m_destroy = true;
} void * thread_work(void* args)
{
for ( int i = 0; i < 20; i++)
{
cout << "the thread output the number: "<< i <<" "<< (char*) args<<endl;
}
} void * dealwithMessage(MSG * msg)
{
MSG tmpMsg;
tmpMsg._msg_count = msg->_msg_count;
tmpMsg._msg_str_message = msg->_msg_str_message; cout << "[INFO]***get the message from the thread***:"<< tmpMsg._msg_str_message << endl;
} void * tread_work1(void *args)
{
for( int i = 0; i< 40; i++)
{
cout <<"another tread output: "<< i <<" "<<(char*) args<< std::endl;
}
} CWork::CWork(){}
CWork::~CWork(){}
void CWork::init(void * args)
{
cout << "this is the class function result: "<< (char*)args <<endl;
} int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread T;
CWork work;
//T.setWorkMethod(thread_work, (void *)"hellowrold");
T.run();
sleep(6);
// T.setWorkMethod(thread_work, (void *)"hellowrold");
T.setWorkMethod(work, (void *)"hellowrold");
// T.setWorkMethod(&work, (void *)"hellowrold");
T.wait();
cout << "the process ending"<< endl;
return 0;
}
//demo4:使用类模板方式,线程调用类方法
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<string> using namespace std;
struct MSG
{
MSG():
_msg_count(),
_msg_str_message("")
{}
int _msg_count;
std::string _msg_str_message;
};
//typedef void *(*methodFunction)(void *);
template<typename T>
class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
int setWorkMethod(T & t, void * args = NULL);
int setSleepTimeForSeconds(int sec);
void sendMessage(void *(*dealMessageFunction)(MSG *), void* type = NULL);
void stop();
void wait();
private:
static void * func_workFunction(void * args);
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
bool m_destroy;
int m_sleepSeconds;
MSG m_msg;
T * m_ptrClass;
}; template<typename T>
CThread<T>::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(),
m_count(),
m_sleepSeconds(),
m_destroy(false),
m_ptrClass(NULL)
{
m_msg._msg_count = ;
m_msg._msg_str_message ="this is a message";
} template<typename T>
CThread<T>::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = ;
} template<typename T>
void CThread<T>::run()
{
m_state = pthread_create(&m_thread, NULL, func_workFunction, this);
} template<typename T>
void CThread<T>::wait()
{
if( == m_state)
{
pthread_join(m_thread, NULL);
}
}
template<typename T>
void * CThread<T>::func_workFunction(void * args)
{
CThread<T> * ptrCThread = (CThread<T> *)args;
while(NULL == ptrCThread->m_WorkFunction && !ptrCThread->m_destroy && ptrCThread->m_ptrClass == NULL)
{
cout << "the thread do nothing, sleep "<< ptrCThread->m_sleepSeconds<<" seconds" << endl;
sleep(ptrCThread->m_sleepSeconds);
}
if(NULL != ptrCThread->m_WorkFunction && !ptrCThread->m_destroy)
{
//cout << "DEBUG:run the function "<< endl;
ptrCThread->m_WorkFunction(ptrCThread->m_args);
//cout << "DEBUG:end the function "<< endl;
}else if(NULL !=ptrCThread->m_ptrClass && !ptrCThread->m_destroy)
{
ptrCThread->m_ptrClass->init(ptrCThread->m_args);
}
} template<typename T>
int CThread<T>::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction;
//cout << "DEBUG:set method "<< endl;
return ;
}
template<typename T>
int CThread<T>::setWorkMethod( T & t, void * args)
{
if(args != NULL)
{
m_args = args;
}
m_ptrClass = &t;
}
template<typename T>
void CThread<T>::sendMessage(void *(*dealMessageFunction)(MSG *), void* type)
{
if(!m_msg._msg_str_message.empty())
{
if(NULL == type)
{
dealMessageFunction(&m_msg);
}else
{ }
}
} template<typename T>
int CThread<T>::setSleepTimeForSeconds(int sec)
{
if(sec > )
{
m_sleepSeconds = sec;
}
} template<typename T>
void CThread<T>::stop()
{
m_destroy = true;
} void * thread_work(void* args)
{
for ( int i = ; i < ; i++)
{
cout << "the thread output the number: "<< i <<" "<< (char*) args<<endl;
}
} void * dealwithMessage(MSG * msg)
{
MSG tmpMsg;
tmpMsg._msg_count = msg->_msg_count;
tmpMsg._msg_str_message = msg->_msg_str_message; cout << "[INFO]***get the message from the thread***:"<< tmpMsg._msg_str_message << endl;
} void * tread_work1(void *args)
{
for( int i = ; i< ; i++)
{
cout <<"another tread output: "<< i <<" "<<(char*) args<< std::endl;
}
} class CWork
{
public:
CWork();
~CWork();
void init(void *);
};
CWork::CWork(){}
CWork::~CWork(){}
void CWork::init(void * args)
{
cout << "this is the class function "<< (char*)args <<endl;
} int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread<CWork> T;
CWork work;
//T.setWorkMethod(thread_work, (void *)"hellowrold");
T.run();
sleep();
//T.setWorkMethod(thread_work, (void *)"hellowrold");
T.setWorkMethod(work, (void *)"hellowrold");
// T.setWorkMethod(&work, (void *)"hellowrold");
T.wait();
cout << "the process ending"<< endl;
return ;
}
// worker is changed
#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<string> #define FREE 0
#define BUSY 1
using namespace std;
struct MSG
{
MSG():
_msg_count(),
_msg_str_message("")
{}
int _msg_count;
std::string _msg_str_message;
};
//typedef void *(*methodFunction)(void *);
template<typename T>
class CThread
{
public:
CThread();
~CThread();
void run();
int setWorkMethod(void *(*methodFunction)(void *), void * args = NULL);
int setWorkMethod(T & t, void * args = NULL);
int setSleepTimeForSeconds(int sec);
void sendMessage(void *(*dealMessageFunction)(MSG *), void* type = NULL);
void stop();
void wait();
private:
static void * func_workFunction(void * args);
void *(*m_WorkFunction)(void *);
void *m_args;
pthread_t m_thread;
int m_count;
int m_state;
bool m_destroy;
int m_sleepSeconds;
MSG m_msg;
T * m_ptrClass;
}; template<typename T>
CThread<T>::CThread():
m_WorkFunction(NULL),
m_args(NULL),
m_state(),
m_count(),
m_sleepSeconds(),
m_destroy(false),
m_ptrClass(NULL)
{
m_msg._msg_count = ;
m_msg._msg_str_message ="this is a message";
} template<typename T>
CThread<T>::~CThread()
{
m_WorkFunction = NULL;
m_args = NULL;
m_state = ;
} template<typename T>
void CThread<T>::run()
{
m_state = pthread_create(&m_thread, NULL, func_workFunction, this);
} template<typename T>
void CThread<T>::wait()
{
if( == m_state)
{
pthread_join(m_thread, NULL);
}
}
template<typename T>
void * CThread<T>::func_workFunction(void * args)
{
CThread<T> * ptrCThread = (CThread<T> *)args;
while(NULL == ptrCThread->m_WorkFunction && !ptrCThread->m_destroy && ptrCThread->m_ptrClass == NULL)
{
cout << "the thread do nothing, sleep "<< ptrCThread->m_sleepSeconds<<" seconds" << endl;
sleep(ptrCThread->m_sleepSeconds);
}
if(NULL != ptrCThread->m_WorkFunction && !ptrCThread->m_destroy)
{
//cout << "DEBUG:run the function "<< endl;
ptrCThread->m_WorkFunction(ptrCThread->m_args);
//cout << "DEBUG:end the function "<< endl;
}else if(NULL !=ptrCThread->m_ptrClass && !ptrCThread->m_destroy)
{
ptrCThread->m_ptrClass->init(ptrCThread->m_args);
}
} template<typename T>
int CThread<T>::setWorkMethod(void *(*methodFunction)(void *), void * args)
{
if(args != NULL)
{
m_args = args;
}
m_WorkFunction = methodFunction;
//cout << "DEBUG:set method "<< endl;
return ;
}
template<typename T>
int CThread<T>::setWorkMethod( T & t, void * args)
{
if(args != NULL)
{
m_args = args;
}
m_ptrClass = &t;
}
template<typename T>
void CThread<T>::sendMessage(void *(*dealMessageFunction)(MSG *), void* type)
{
if(!m_msg._msg_str_message.empty())
{
if(NULL == type)
{
dealMessageFunction(&m_msg);
}else
{ }
}
} template<typename T>
int CThread<T>::setSleepTimeForSeconds(int sec)
{
if(sec > )
{
m_sleepSeconds = sec;
}
} template<typename T>
void CThread<T>::stop()
{
m_destroy = true;
} void * thread_work(void* args)
{
for ( int i = ; i < ; i++)
{
cout << "the thread output the number: "<< i <<" "<< (char*) args<<endl;
}
} void * dealwithMessage(MSG * msg)
{
MSG tmpMsg;
tmpMsg._msg_count = msg->_msg_count;
tmpMsg._msg_str_message = msg->_msg_str_message; cout << "[INFO]***get the message from the thread***:"<< tmpMsg._msg_str_message << endl;
} void * tread_work1(void *args)
{
for( int i = ; i< ; i++)
{
cout <<"another tread output: "<< i <<" "<<(char*) args<< std::endl;
}
} class CWork
{
public:
CWork();
~CWork();
void init(void *);
void start(char * args = NULL);
private:
int m_state;
string m_strMsg;
};
CWork::CWork():m_state(FREE){}
CWork::~CWork(){}
void CWork::init(void * args)
{
while(m_state == FREE)
{
cout << "this is the class work function "<< (char*)args <<endl;
sleep();
cout << "wait msg"<<endl;
}
while(m_state == BUSY)
{
cout << "the work start wokrking, the work message is :"<< m_strMsg<<endl;
sleep(); }
/*
for( int i = 0; i < 100 ; i++)
{
cout << "the work start wokrking, the work message is :"<< m_strMsg<<endl;
}
*/ }
void CWork::start(char * args)
{
if( NULL == args)
{
std::cout <<"the start args is none, so nothing to do "<< std::endl;
}else
{
m_strMsg = args;
m_state = BUSY;
}
}
int main(int argc, char * argv[])
{
cout << "test for thread class" <<endl;
CThread<CWork> T;
CWork work;
T.run();
for(int i =;i <; i++)
{
std::cout << "main thread message:first -----" <<i <<std::endl;
} sleep();
cout<<"********set the thread worker"<<endl;
T.setWorkMethod(work, (void *)"hellowrold");
for(int i =;i <; i++)
{
std::cout << "main thread message:second -----" <<i <<std::endl;
}
string strinput;
while(cin>>strinput)
{
cout << strinput << endl;
if(strinput.compare("q") == )
break;
}
cout<<"********set the worker start state"<<endl;
work.start("we have a good way to work");
strinput.clear();
while(cin>>strinput)
{
cout << strinput << endl;
if(strinput.compare("q") == )
break;
}
for(int i =;i <; i++)
{
std::cout << "main thread message:" <<i <<std::endl;
}
// sleep(6);
//T.stop();
T.wait();
cout << "the process ending"<< endl;
return ;
}
linux c++自己使用pthread封装的线程类的更多相关文章
- MFC--串口编程---WIN API的方式将串扣操作封装在线程类中
串口采集数据 本文档介绍的是如何获取串口原始数据并将原始数据解析成可处理或可展示的数据. 一.串口采集有很多方式: 1).MFC有一个专门的控件,直接编程采集,一个控件只能采集一个串口,而且串口名字比 ...
- 转:一个跨WINDOWS LINUX平台的线程类
来源:http://blog.csdn.net/dengxu11/article/details/7232681 继Windows下实现一个CThread封装类之后,这里我再实现一个跨WINDOWS ...
- [转] Linux多线程编程之pthread
转载出处:https://blog.csdn.net/skyroben/article/details/72793409 1.背景知识 Linux没有真正意义上的线程,它的实现是由进程来模拟,所以属于 ...
- Linux系统监控命令及定位Java线程
1.PID.TID的区分 uid是user id,即用户id,root用户的uid是0,0为最高权限,gid是group id,用户组id,使用 id 命令可以很简单的通过用户名查看UID.GID:~ ...
- Linux下的进程类别(内核线程、轻量级进程和用户进程)--Linux进程的管理与调度(四)
本文中出现的,内核线程,轻量级进程,用户进程,用户线程等概念,如果不太熟悉, 可以参见 内核线程.轻量级进程.用户线程三种线程概念解惑(线程≠轻量级进程) Linux进程类别 虽然我们在区分Linux ...
- linux内核——会话、进程组、线程组
会话.进程组.线程组总体关系示意图 待插入 Session(会话)与进程组 Shell 分前后台来控制的不是进程而是作业(Job)或者进程组(Process Group).一个前台作业可以由多个进程组 ...
- Linux 平台如何查看某个进程的线程数?
Linux 平台如何查看某个进程的线程数? 三种方法:1. 使用top命令,具体用法是 top -H 加上这个选项,top的每一行就不是显示一个进程,而是一个线程. 2. 使用ps命令,具体用法是 ...
- Linux有问必答:Linux上如何查看某个进程的线程
原创:LCTT https://linux.cn/article-5633-1.html 译者: GOLinux本文地址:https://linux.cn/article-5633-1.html201 ...
- 【摘】Linux虚拟地址空间布局以及进程栈和线程栈总结
在CSDN上看到的一篇文章,讲的还是满好的. 原文地址:Linux虚拟地址空间布局以及进程栈和线程栈总结 一:Linux虚拟地址空间布局 (转自:Linux虚拟地址空间布局) 在多任务操作系统中,每个 ...
随机推荐
- 【计算几何】bzoj2338 [HNOI2011]数矩形
对于两条线段,若其中点重合,且长度相等,那么它们一定是某个矩形的对角线. N*N地处理出所有线段,排序,对每一部分中点重合.长度相等的线段进行暴力枚举,更新答案. 用 long double 注意EP ...
- Bootstrap-table实现动态合并相同行(表格同名合并)
写在前面: 有时候表格的需求就是奇奇怪怪的,最近要做的表格需要实现当紧挨着的记录的某一列的行元素内容相同,就将其合并.要是不是相同的就不合并.如果表格数据的顺序不需要被改变,这个样子是可以很简单就完成 ...
- TZOJ 数据结构实验:单链表元素插入
描述 实现函数CreateHeader用于创建空链表,实现Insert函数并调用它完成带头节点链表的创建. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. void PrintLinkL ...
- java读写文件及保留指定位小数
1)先上代码: public static void main(String[] args)throws IOException{ double[][] B=new double[1043][2102 ...
- JavaScript的=、==和===
(1) 百度知道上的解释: = 为对象赋值 == 表示两个对象toString值相等 === 表示两个对象类型相同且值相等 (2) 知乎上的解释: 绝大多数场合应该使用 === ,只有检测 null ...
- easyui textbox获取焦点事件
$('#textboxid').textbox().next('span').find('input').focus(); $('#id').textbox('textbox').focus();
- javascript正则表达式(regular expression)
一种字符串匹配的模式,用来检查一个串是否含有某种子串.将匹配的子串替换或者从某个串中取出符合某个条件的子串等.注意:在javascript中正则表达式也是一种对象1:创建正则表达式两种方式:隐式创建( ...
- 初识JdbcTemplate
1.spring配置文件里注冊:參照使用 Spring jdbcTemplate 进一步简化 JDBC 操作 2.写javabean 3.写rowmapper(依据javabean来封装结果集) 4. ...
- Vue实例总结
一.登陆框的要点总结: 1.暂无数据就是要myData里没数据时候才出来:删除全部就是要有数据才出来.v-show的使用: 2.表格行就是需要循环数据,v-for.{{$index}}.{{item. ...
- c3p0配置详解<转贴>
<c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: 3 --> < ...