Saturday, April 28, 2012

看了这么多遍“Les Misérables”,总被不同的人感动


“Who am I? Who am I?
 I am Jean Valjean!”
Valjean的担当和勇气感动过我,那时我小学!
"For this man has spoken true
I commend you for your duty
And God's blessing go with you."
主教的宽容和无私感动过我,那时我中学!
“Drink with me to days gone by
Can it be you fear to die?
Will the world remember you 
When you fall? 
Could it be your death 
Means nothing at all? 
Is your life just one more lie?”
学生的献身和友谊感动过我,那时我大学!
曾经最不理解的当属Javet,尤其是他最后的自杀!为什么一个高呼“the man like you”的卫道士,会放走逃犯并用自己的生命来为Valjean脱罪?
今天忽然好像理解了...他的精神支柱没有了,一个耗尽心血的目标,忽然消失了...死亡也许是最合理和最有尊严的选择!
一个踌躇满志的斗士,向孤星发誓,发誓独自承受痛苦,只为心中闪光的那个理想--法律与公平!
“Lord let me find him
That I may see him
Safe behind bars
I will never rest
Till then
This I swear
This I swear by the stars!”
一个满头白发的失意者,勇敢的承认了现实...法律和公平已经黯淡,自己以无力改变!但一颗冰冷的心,又怎么能注入曾经厌恶的“人性”呢?
“I am reaching but I fall
And the stars are black and cold
As I stare into the void
Of a world that cannot hold
I'll escape now from that world
From the world of Jean Valjean.
There is nowhere I can turn
There is now way to go on...”
每个人都曾感叹理想的伟大,后来感叹世界的悲惨!最后承认个人的无助与渺小!
没经历的人怎么会知道?知道的人有怎么把这些写下来?雨果都做到了!

Sunday, April 22, 2012

How to define your own container and iterator

I want to define a simple wrapper class of “std” container. The meaning of the following code is to provide a Qt style container interface for some legacy C++ code segments with Qt. The key point below is

typedef typename map<KEY,VALUE>::iterator iterator;
Because the compiler does not know the following token, so we need explicitly declare “typename” to tell the compiler that the coming token is the name of a type.
The following is the whole declaration and implementation. 



   1:  #ifndef MYMAP_H
   2:  #define MYMAP_H
   3:   
   4:  #include <map>
   5:  using namespace std;
   6:   
   7:  template <class KEY, class VALUE>
   8:  class MyMap
   9:  {
  10:  public:
  11:      MyMap();
  12:      bool contains( KEY data );
  13:      VALUE value( KEY data );
  14:      void insert( KEY key, VALUE value );
  15:      typedef typename map<KEY,VALUE>::iterator iterator;
  16:  private:
  17:      map<KEY,VALUE> _data;
  18:  };
  19:   
  20:  template<class KEY, class VALUE>
  21:  MyMap<KEY, VALUE>::MyMap()
  22:  {
  23:      return;
  24:  }
  25:   
  26:  template<class KEY, class VALUE>
  27:  bool MyMap<KEY, VALUE>::contains( KEY data )
  28:  {
  29:      MyMap<KEY, VALUE>::iterator iter = this->_data.find( data );
  30:      if( iter != this->_data.end() )
  31:      {
  32:          return true;
  33:      }
  34:      else
  35:      {
  36:          return false;
  37:      }
  38:  }
  39:  //
  40:  template<class KEY, class VALUE>
  41:  VALUE MyMap<KEY, VALUE>::value( KEY data )
  42:  {
  43:      MyMap<KEY, VALUE>::iterator iter = this->_data.find( data );
  44:      if( iter != this->_data.end() )
  45:      {
  46:          return iter->second;
  47:      }
  48:      else
  49:      {
  50:          return 0;
  51:      }
  52:  }
  53:  //
  54:  template<class KEY, class VALUE>
  55:  void MyMap<KEY, VALUE>::insert( KEY key, VALUE value )
  56:  {
  57:      this->_data.insert( make_pair( key, value ) );
  58:      return;
  59:  }
  60:   
  61:  #endif

Saturday, April 14, 2012

What is behind the auto focus(AF)

Auto focus is a very useful and typical function in current digital cameras and cellphone cameras. As I will work on some code about the Android autofocus, I read some martials from Wikipedia and this.

First, we define what is AF. A camera`s autofocus system intelligently adjusts the camera lens to obtain focus on the subject, and can mean the difference between a sharp photo and a missed opportunity. The process of autofocusing generally works as followed:

1) An autofocus processor(AFP) makes a small change in the focusing distance;

2) AFP reads the AF sensor to assess whether and by how much focus has improved;

3) Using the information form (2), the AFP sets the lens to a new focusing distance;

4) The AFP may iteratively repeat steps 2-3 until satisfactory focus has been achieved.

The entire process is usually completed within a fraction of a second. For difficult subjects, the camera may fail to achieve satisfactory focus and will give up on repeating the above sequence, resulting in failed autofocus.