Saturday, April 28, 2012

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

“Who am I? Who am I?
 I am Jean 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
   4:  #include <map>
   5:  using namespace std;
   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:  };
  20:  template<class KEY, class VALUE>
  21:  MyMap<KEY, VALUE>::MyMap()
  22:  {
  23:      return;
  24:  }
  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:  }
  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.