tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

比如这句话是不行的:
update ERP_Invoice set WriteOffDeadline='2011-1-1' where id in (2,3)
应该是这样才对:
update ERP_Invoice set WriteOffDeadline='2011-01-01' where id in (2,3)

posted @ 2011-06-22 18:18 Tommy Liang 阅读(1126) | 评论 (0)编辑 收藏

 Warning: No relevant classes found. No output generated

百思不得其解之下,想起来有个注释是从word拷过来的,当时提示了一下需要unicode保存,没留意。。。

检查头文件,果然是unicode编码,改为gb2312,编译通过。

posted @ 2011-06-22 00:06 Tommy Liang 阅读(2210) | 评论 (0)编辑 收藏



posted @ 2011-06-19 16:09 Tommy Liang 阅读(331) | 评论 (0)编辑 收藏

think about the grid listeners of grid, it's so complicate that it's hard to maintain relationship  and status,I think it's necessary to arose an intermediate level to cope with this;
perhaps like this:

//somewhere in A.hpp ...
Grid A("guid_a");
//somewhere else in B.hpp
Grid B("guid_b");
//somewhere else in C.hpp
Form c("guid_c");

A.AddListener("guid_b");      //why use string but not directly object pointer? because perhaps listeners is not yet valid at this runtime, this is just a registeration work
A.AddListener("guid_c");

//cope with the code when A select a row:
GridListenerHandler handler(A);
handler.HandleListeners();

//how to handle? like follow:
Context context = ...;
BOOST_FOREACH(shared_ptr<IListener> listener, InnerGetListeners())
{
       listener->Execute(context);
}

posted @ 2011-05-24 13:10 Tommy Liang 阅读(209) | 评论 (0)编辑 收藏

不能在构造函数中使用 shared_from_this,正确的做法如下:google自: http://boost.2283326.n4.nabble.com/enabled-shared-from-this-bad-weak-ptr-exception-online-doc-explanation-td2583370.html

Since in the current version you cannot call shared_from_this() in a 
constructor, you can't initialize your members with an expression that 
invloves shared_from_this(). Instead, you can set your shared_ptr's in 
some initializing member function that would be called after the 
object is constructed: 

struct B; 
struct A 
{ 
  A(shared_ptr<B> b) 
  { 
    //... 
  } 
}; 

class B : public enable_shared_from_this<B> 
{ 
  shared_ptr<A> a_; 
public: 
  void init() 
  { 
    a_.reset(new A(shared_from_this())); 
  } 
}; 

main() 
{ 
  shared_ptr<B> b(new B); 
  b->init(); 
} 

...also you can wrap initialization in a static constructing function: 

class B.... 
{ 
  // like in the previous example 
  B() 
  {} 
public: 
  static shared_ptr<B> create() 
  { 
    shared_ptr<B> result(new B()); 
    result->init(); 
    return result; 
  } 
}; 

main() 
{ 
  shared_ptr<B> b(B::create()); 
} 

posted @ 2011-03-24 23:29 Tommy Liang 阅读(998) | 评论 (0)编辑 收藏

Use scoped_ptr when

  • A pointer is used in a scope where an exception may be thrown

  • There are several control paths in a function

  • The lifetime of a dynamically allocated object can be limited to a specific scope

  • Exception safety is important (always!)

Use shared_ptr in the following scenarios:

      When there are multiple clients of an object, but no explicit owner

  • When storing pointers in Standard Library containers

  • When passing objects to and from libraries without (other) expressed ownership

  • When managing resources that need special cleanup[9]

Use weak_ptr to

  • Break cyclic dependencies

  • Use a shared resource without sharing ownership

  • Avoid dangling pointers


check:http://my.oschina.net/jackwgm/blog/6695?catalog=23886

posted @ 2011-03-23 10:01 Tommy Liang 阅读(228) | 评论 (0)编辑 收藏

1.矩阵乘以向量即为使用向量的分量对矩阵的列进行线性组合;
2.每个消元步骤都可以用矩阵乘法表达;由此导出求逆的办法:
  E[A I]表明对 [A I]分块矩阵进行消元,消元的步骤归结为 E,则得到 [EA E],EA最终变成I,那么E就是A-,其值由[EA E](即[I E])的右边分块给出。
3.矩阵乘法可以改变组合顺序(重新组合括号),但不可交换;
4.矩阵在左边的时候,用行变换,在右边的时候,用列变换;
5.行操作的步骤:选择左边矩阵每行的分量作为组合因子,对右边矩阵的各行进行线性组合,产生对应的各行;
6.列操作的步骤:选择右边矩阵每列(向量)的分量作为组合因子,对左边矩阵的各列进行线性组合,产生对应的各列;
7.置换矩阵:行交换后的单位矩阵;
8.置换矩阵的特点:总是可逆的,并且其转置恰好等于其逆;
9.PA=LU, 矩阵总可做LU分解,P是置换矩阵(Permutation);
10.对称矩阵:转置后等于自身的矩阵;
11.矩阵乘上其转置可以产生一个对称矩阵;
12.向量空间:即若干向量的线性组合;
  线性无关:如果向量无论如何组合(除了零组合)都得不到零向量,那么这些向量就是线性无关的,反之就是线性相关的,简言之,如果 Ax = 0 无解(零解除外),则A的列向量线性无关。
 (矩阵的)零空间(NA):使得Ax=0的所有x,总是包括零向量,零空间告诉我们矩阵的列向量是如何组合使得他们线性相关的;
13.Ax=b的可解性分析:首先b必须在C(A)(A的列空间)中,第二是如果A的行的某个线性组合产生了零行,那么b的同样的线性组合必须也给出零;
14.如何找到Ax=b的全解集:
   (1)找到一个特解:首先将所有的自由变量设置为零,然后为解Ax=0得到主元,比如R4中,x1,x3是主元,解出特解为 [x1,0,x3,0]T
   (2)解x的零空间(null space);
   现在,全解的表达式就是 特解 + 零空间中x的任意线性组合;
15.矩阵的秩(Rank):消元后有主元的列数;
16.m x n 矩阵的秩r与Ax=b的解集的关系:
   (1)r = m = n
       其 rref (reduced row echelon form:矩阵的化简行阶梯形式) 是单位矩阵I,Ax=b有唯一解;
   (2)r = n < m
       其 rref 形如 [I 0]零解或一个解,当b的下面的对应rref的零块的分量不是0的话,就是零解;
   (3)r = m < n
       其 rref 形如 [IF],F是自由变量,有无穷多个解;
   (4)r < m,r < n
       其 rref 形如 [IF  00]T ,有零或无穷解;
17.如果矩阵的零空间只有零向量,那么矩阵的向量线性无关 (independent),可以理解为:除了零,没有其他线性组合使得矩阵的向量回到原点,则向量线性无关;
18.张成(Span):矩阵列向量的所有线性组合;
19.空间的基(Basis):{ 空间中的向量集 | 线性无关且可张成空间本身 },某个空间的所有基都有相同个数的向量数,这个数称为空间的维(Dimension),
   其中,DimC(A)=r, DimN(A) = n - r
20.矩阵的四个子空间:
   (1)C(A) 列空间,在 Rm,向量有m个分量,Dim(C(A)) = r;
   (2)N(A) 零空间,在 Rn,Dim(N(A)) = n-r
   (3)C(AT) 行空间,在 Rn,Dim(C(AT)) = r,即矩阵转置后,列空间的维度不变;这是一个很重要的结论。
   (4)N(AT) 转置的零空间,在 Rm,Dim(N(AT)) = m-r


今天到西丽考第一科目,100分过关!特此庆祝!

posted @ 2011-01-18 13:43 Tommy Liang 阅读(1773) | 评论 (0)编辑 收藏

四元数常常可以在3D的书上看到。
但我的那本3D图形学书上,在没讲四元数是干什么的之前,就列了几张纸的公式,
大概因为自己还在上高中,不知道的太多,看了半天没看懂。。。
终于,在gameres上看到了某强人翻译的一个“4元数宝典 ”(原文是日本人写的。。。),感觉很好,分享下。

★旋转篇:
 我将说明使用了四元数(si yuan shu, quaternion)的旋转的操作步骤
)四元数的虚部,实部和写法
所谓四元数,就是把4个实数组合起来的东西。
4个元素中,一个是实部,其余3个是虚部。
比如,叫做Q的四元数,实部t而虚部是x,y,z构成,则像下面这样写。
= (t; x, y, z) 
又,使用向量 V
=(x,y,z),
= (t; V)  
也可以这么写。

正规地用虚数单位i,j,k的写法的话,
= t + xi + yj + zk 
也这样写,不过,我不大使用

)四元数之间的乘法
虚数单位之间的乘法 
ii 
= -1, ij = -ji = k (其他的组合也是循环地以下同文) 
有这么一种规则。(我总觉得,这就像是向量积(外积),对吧) 
用这个规则一点点地计算很麻烦,所以请用像下面这样的公式计算。

= (a; U) 
= (b; V) 
AB 
= (ab - U·V; aV + bU + U×V)
不过,“U·V”是内积,「U×V」是外积的意思。
注意:一般AB
<>BA所以乘法的左右要注意!

3)3次元的坐标的四元数表示
如要将某坐标(x,y,z)用四元数表示,
= (0; x, y, z) 
则要这么写。
 
另外,即使实部是零以外的值,下文的结果也一样。用零的话省事所以我推荐。

)旋转的四元数表示
以原点为旋转中心,旋转的轴是(α, β, γ)
(但 α
^2 + β^2 + γ^2 = 1), 
(右手系的坐标定义的话,望向向量(α, β, γ)的前进方向反时针地) 
转θ角的旋转,用四元数表示就是,
= (cos(θ/2); α sin(θ/2), β sin(θ/2), γ sin(θ/2)) 
= (cos(θ/2); -α sin(θ/2), -β sin(θ/2), -γ sin(θ/2)) 
(另外R 叫 Q 的共轭四元数。) 

那么,如要实行旋转,
则 R P Q 
= (0; 答案) 

请像这样三明治式地计算。这个值的虚部就是旋转之后的点的坐标值。
 (另外,实部应该为零。请验算看看) 

例子代码

/// Quaternion.cpp 
/// (C) Toru Nakata, toru-nakata@aist.go.jp 
/// 2004 Dec 29 
  
#include 
<math.h> 
#include 
<iostream.h> 
  
/// Define Data type 
typedef struct 

              
double t; // real-component 
              double x; // x-component 
              double y; // y-component 
              double z; // z-component 
} quaternion; 
  

//// Bill 注:Kakezan 在日语里是 “乘法”的意思
quaternion Kakezan(quaternion left, quaternion right) 

              quaternion ans; 
              
double d1, d2, d3, d4; 
  
              d1 
=  left.t * right.t; 
              d2 
= -left.x * right.x; 
              d3 
= -left.y * right.y; 
              d4 
= -left.z * right.z; 
              ans.t 
= d1+ d2+ d3+ d4; 
  
              d1 
=  left.t * right.x; 
              d2 
=  right.t * left.x; 
              d3 
=  left.y * right.z; 
              d4 
= -left.z * right.y; 
              ans.x 
=  d1+ d2+ d3+ d4; 
  
              d1 
=  left.t * right.y; 
              d2 
=  right.t * left.y; 
              d3 
=  left.z * right.x; 
              d4 
= -left.x * right.z; 
              ans.y 
=  d1+ d2+ d3+ d4; 
  
              d1 
=  left.t * right.z; 
              d2 
=  right.t * left.z; 
              d3 
=  left.x * right.y; 
              d4 
= -left.y * right.x; 
              ans.z 
=  d1+ d2+ d3+ d4; 
              
              
return ans; 

  
//// Make Rotational quaternion 
quaternion MakeRotationalQuaternion(double radian, double AxisX, double AxisY, double AxisZ) 

              quaternion ans; 
              
double norm; 
              
double ccc, sss; 
              
              ans.t 
= ans.x = ans.y = ans.z = 0.0
  
              norm 
= AxisX *  AxisX +  AxisY *  AxisY +  AxisZ *  AxisZ; 
              
if(norm <= 0.0return ans; 
  
              norm 
= 1.0 / sqrt(norm); 
              AxisX 
*= norm; 
              AxisY 
*= norm; 
              AxisZ 
*= norm; 
  
              ccc 
= cos(0.5 * radian); 
              sss 
= sin(0.5 * radian); 
  
              ans.t 
= ccc; 
              ans.x 
= sss * AxisX; 
              ans.y 
= sss * AxisY; 
              ans.z 
= sss * AxisZ; 
  
              
return ans; 

  
//// Put XYZ into  quaternion 
quaternion PutXYZToQuaternion(double PosX, double PosY, double PosZ) 

              quaternion ans; 
  
              ans.t 
= 0.0
              ans.x 
= PosX; 
              ans.y 
= PosY; 
              ans.z 
= PosZ; 
  
              
return ans; 

  
///// main 
int main() 

              
double px, py, pz; 
              
double ax, ay, az, th; 
              quaternion ppp, qqq, rrr; 
  
              cout 
<< "Point Position (x, y, z) " << endl; 
              cout 
<< "  x = "
              cin 
>> px; 
              cout 
<< "  y = "
              cin 
>> py; 
              cout 
<< "  z = "
              cin 
>> pz; 
              ppp 
= PutXYZToQuaternion(px, py, pz); 
  
              
while(1) { 
                            cout 
<< "\nRotation Degree ? (Enter 0 to Quit) " << endl; 
                            cout 
<< "  angle = "
                            cin 
>> th; 
                            
if(th == 0.0break
  
                            cout 
<< "Rotation Axis Direction ? (x, y, z) " << endl; 
                            cout 
<< "  x = "
                            cin 
>> ax; 
                            cout 
<< "  y = "
                            cin 
>> ay; 
                            cout 
<< "  z = "
                            cin 
>> az; 
  
  
                            th 
*= 3.1415926535897932384626433832795 / 180.0/// Degree -> radian; 
  
                            qqq 
= MakeRotationalQuaternion(th, ax, ay, az); 
                            rrr 
= MakeRotationalQuaternion(-th, ax, ay, az); 
  
                            ppp 
= Kakezan(rrr, ppp); 
                            ppp 
= Kakezan(ppp, qqq); 
  
                            cout 
<< "\nAnser X = " << ppp.x 
                                          
<<  "\n      Y = " << ppp.y 
                                          
<<  "\n      Z = " << ppp.z << endl; 
  
              } 
  
              
return 0
}  

posted @ 2010-10-21 17:26 Tommy Liang 阅读(8495) | 评论 (0)编辑 收藏

snprintf函数并不是标准c/c++中规定的函数,但是在许多编译器中,厂商提供了其实现的版本。
在gcc中,该函数名称就snprintf,而在VC中称为_snprintf。
  由于不是标准函数,没有一个统一的标准来规定该函数的行为,所以导致了各厂商间的实现版本可
能会有差异。今天也的的确确看到了差异,因为这个小小的差异是我的程序无法正常的处理数据。
  这个小小的差异发生在count参数。在VC中,这个count就是要写入的总字符串字符数,例如:

    
//VC
int main(int argc, char* argv[])
{
    
char   buff[100
];
     printf(
"%d ",_snprintf(buff,10,"1234567890ab"
));
     printf(
"%s"
,buff);
    
return0
;
}


//Linxu:gcc/g++
#include <stdio.h>
int main(int argc, char* argv[])
{
    
char   buff[100
];
     printf(
"%d ",snprintf(buff,10,"1234567890ab"
));
     printf(
"%s"
,buff);
    
return0
;
}

posted @ 2010-09-21 21:38 Tommy Liang 阅读(348) | 评论 (0)编辑 收藏

在如下系列中:

1、QSqlQuery q("select count(*) from sometable where name=:name");
   ...
2、QSqlDatabase::database().transaction();
   ....

在1和2之间如果不清除q,是会锁死的,答案在这里:

bool QSqlDatabase::commit ()

Commits a transaction to the database if the driver supports transactions and a transaction() has been started. Returns true if the operation succeeded. Otherwise it returns false.

Note: For some databases, the commit will fail and return false if there is an active query using the database for a SELECT. Make the query inactive before doing the commit.

Call lastError() to get information about errors.

See also QSqlQuery::isActive(), QSqlDriver::hasFeature(), and rollback().

posted @ 2010-09-12 09:16 Tommy Liang 阅读(570) | 评论 (0)编辑 收藏

仅列出标题
共6页: 1 2 3 4 5 6