images::ImagesDocument Class Reference

Handle images file format. More...

#include <images_document.h>

Collaboration diagram for images::ImagesDocument:
Collaboration graph
[legend]

Public Member Functions

 ImagesDocument (void)
 ~ImagesDocument (void)
bool open_document (const std::string &path, bool to_scan_dir=true)
 Open .images index file.
bool is_open ()
 Check if the document has been opened.
unsigned int page_count ()
 How many "page" does it contain.
int get_initial_page_num ()
 Get the initial page number.
const ImagePtr get_page (const unsigned int page_number)
 Retrieve specified page.
int get_page (const std::string &anchor)
 Retrieve page from anchor.
bool get_page_name (const std::string &anchor, std::string &name)
bool close_document ()
 Close and release all allocated resource.
bool get_anchor_of_page (const unsigned int page_number, std::string &anchor)
bool has_anchor (const std::string &anchor)
 Check the document contains the anchor or not.
int get_position (const std::string &anchor)
 Find position from the anchor.
int compare_anchor (const std::string &first, const std::string &second)
 Compare the anchor object.
bool get_prev_page (std::string &anchor)
 Anchor iteraotr: retrieve the previous anchor.
bool get_next_page (std::string &anchor)
 Anchor iteraotr: retrieve the next anchor.
bool get_original_size (const std::string &anchor, unsigned int &width, unsigned int &height)
bool get_original_rotation (const std::string &anchor, PluginRotationDegree &rotation)

Detailed Description

Handle images file format.

Definition at line 38 of file images_document.h.


Constructor & Destructor Documentation

images::ImagesDocument::ImagesDocument ( void   ) 

Definition at line 40 of file images_document.cpp.

References LOGPRINTF.

00040                                    : initial_page_num(1)
00041 {
00042     LOGPRINTF("entry");
00043 }

images::ImagesDocument::~ImagesDocument ( void   ) 

Definition at line 45 of file images_document.cpp.

References close_document(), and LOGPRINTF.

00046 {
00047     LOGPRINTF("entry");
00048 
00049     close_document();
00050 }

Here is the call graph for this function:


Member Function Documentation

bool images::ImagesDocument::close_document (  ) 

Close and release all allocated resource.

Definition at line 99 of file images_document.cpp.

References LOGPRINTF.

Referenced by ~ImagesDocument().

00100 {
00101     LOGPRINTF("entry");
00102 
00103     ImagesIter begin = images.begin();
00104     ImagesIter end   = images.end();
00105     for(ImagesIter iter = begin; iter != end; ++iter)
00106     {
00107         delete *iter;
00108     }
00109     images.clear();
00110     return true;
00111 }

Here is the caller graph for this function:

int images::ImagesDocument::compare_anchor ( const std::string &  first,
const std::string &  second 
)

Compare the anchor object.

Definition at line 139 of file images_document.cpp.

References get_position(), and LOGPRINTF.

00141 {
00142     int first_pos = get_position(first);
00143     int second_pos = get_position(second);
00144 
00145     LOGPRINTF("first_pos[%d] second_pos[%d]", first_pos, second_pos);
00146 
00147     return first_pos - second_pos;
00148 }

Here is the call graph for this function:

bool images::ImagesDocument::get_anchor_of_page ( const unsigned int  page_number,
std::string &  anchor 
)

Anchor policy: Use path name of image as the anchor. Get anchor for specified page.

Definition at line 113 of file images_document.cpp.

References LOGPRINTF, and path.

Referenced by main().

00115 {
00116     LOGPRINTF("entry %d", page_number);
00117 
00118     if (page_number >= 1 && page_number <= images.size())
00119     {
00120         anchor = images[page_number - 1]->path;
00121 
00122         LOGPRINTF("%s", images[page_number -1]->path.c_str());
00123 
00124         return true;
00125     }
00126     else
00127     {
00128         return false;
00129     }
00130 }

Here is the caller graph for this function:

int images::ImagesDocument::get_initial_page_num (  ) 

Get the initial page number.

Definition at line 83 of file images_document.cpp.

00084 {
00085     return initial_page_num;
00086 }

bool images::ImagesDocument::get_next_page ( std::string &  anchor  ) 

Anchor iteraotr: retrieve the next anchor.

Definition at line 206 of file images_document.cpp.

References LOGPRINTF.

00207 {
00208     ImagesIter begin = images.begin();
00209     ImagesIter end   = images.end();
00210     ImagesIter iter;
00211     for(iter = begin; iter != end; ++iter)
00212     {
00213         if ((*iter)->path == anchor)
00214         {
00215             break;
00216         }
00217     }
00218     
00219     if (iter == end || ++iter == end)
00220     {
00221         return false;
00222     }
00223     anchor = (*iter)->path;
00224 
00225     LOGPRINTF("%s", anchor.c_str());
00226 
00227     return true;
00228 }

bool images::ImagesDocument::get_original_rotation ( const std::string &  anchor,
PluginRotationDegree rotation 
)

Definition at line 265 of file images_document.cpp.

00267 {
00268      ImagesIter begin = images.begin();
00269      ImagesIter end   = images.end();
00270      ImagesIter iter;
00271      for(iter = begin; iter != end; ++iter)
00272      {
00273          if ((*iter)->path == anchor)
00274          {
00275              // The image rotation is not calculated yet, calculate it now.
00276              if ( !((*iter)->is_rotation_calculated) )
00277              {
00278                  ImagesScanner::get_original_rotation((*iter)->path, (*iter)->rotation);
00279                  (*iter)->is_rotation_calculated = true;
00280              }
00281 
00282              rotation = (*iter)->rotation;
00283              
00284              return true;
00285          }
00286      }
00287      return false;
00288 }

bool images::ImagesDocument::get_original_size ( const std::string &  anchor,
unsigned int &  width,
unsigned int &  height 
)

Definition at line 230 of file images_document.cpp.

References images::ImagesScanner::get_size().

00233 {
00234      ImagesIter begin = images.begin();
00235      ImagesIter end   = images.end();
00236      ImagesIter iter;
00237      for(iter = begin; iter != end; ++iter)
00238      {
00239          if ((*iter)->path == anchor)
00240          {
00241              // The image size is not calculated yet, calculate it now.
00242              if (((*iter)->width == -1) || ((*iter)->height == -1))
00243              {
00244                  ImagesScanner::get_size((*iter)->path, 
00245                                          &(*iter)->width, 
00246                                          &(*iter)->height);
00247              }
00248              
00249              // The valid image's size is greater than zero.
00250              if (((*iter)->width > 0) && ((*iter)->height > 0))
00251              {
00252                  width = (*iter)->width;
00253                  height = (*iter)->height;
00254                  
00255                  return true;
00256              }
00257              
00258              return false;
00259          }
00260      }
00261      
00262      return false;
00263 }

Here is the call graph for this function:

int images::ImagesDocument::get_page ( const std::string &  anchor  ) 

Retrieve page from anchor.

const ImagePtr images::ImagesDocument::get_page ( const unsigned int  page_number  ) 

Retrieve specified page.

Definition at line 88 of file images_document.cpp.

References LOGPRINTF, and path.

00089 {
00090     assert(page_number >= 1 && page_number <= images.size()); 
00091 
00092     LOGPRINTF("page[%d] %s", 
00093             page_number, 
00094             images[page_number - 1]->path.c_str());
00095     
00096     return images[page_number - 1];
00097 }

bool images::ImagesDocument::get_page_name ( const std::string &  anchor,
std::string &  name 
)

Definition at line 166 of file images_document.cpp.

References filename, get_file_name(), has_anchor(), and MAX_PATH_LEN.

00168 {
00169     if (has_anchor(anchor))
00170     {
00171         char filename[MAX_PATH_LEN];
00172         if (get_file_name(anchor.c_str(), filename, MAX_PATH_LEN))
00173         {
00174             name = filename;
00175             return true;
00176         }
00177     }
00178     return false;
00179 }

Here is the call graph for this function:

int images::ImagesDocument::get_position ( const std::string &  anchor  ) 

Find position from the anchor.

Definition at line 150 of file images_document.cpp.

References LOGPRINTF.

Referenced by compare_anchor(), has_anchor(), and images::ImagesRenderer::render().

00151 {
00152     ImagesIter begin = images.begin();
00153     ImagesIter end   = images.end();
00154     for(ImagesIter iter = begin; iter != end; ++iter)
00155     {
00156         if ((*iter)->path == path)
00157         {
00158             LOGPRINTF("%d", static_cast<int>((iter - begin) + 1));
00159 
00160             return static_cast<int>((iter - begin) + 1);
00161         }
00162     }
00163     return -1;
00164 }

Here is the caller graph for this function:

bool images::ImagesDocument::get_prev_page ( std::string &  anchor  ) 

Anchor iteraotr: retrieve the previous anchor.

Definition at line 181 of file images_document.cpp.

References LOGPRINTF, and path.

00182 {
00183     ImagesIter begin = images.begin();
00184     ImagesIter end   = images.end();
00185     ImagesIter iter;
00186     for(iter = begin; iter != end; ++iter)
00187     {
00188         if ((*iter)->path == anchor)
00189         {
00190             break;
00191         }
00192     }
00193     
00194     // Check the iter position.
00195     if (iter == end || iter == begin)
00196     {
00197         return false;
00198     }
00199     anchor = (*--iter)->path;
00200 
00201     LOGPRINTF("%s", anchor.c_str());
00202 
00203     return true;
00204 }

bool images::ImagesDocument::has_anchor ( const std::string &  anchor  ) 

Check the document contains the anchor or not.

Definition at line 132 of file images_document.cpp.

References get_position(), and LOGPRINTF.

Referenced by get_page_name().

00133 {
00134     LOGPRINTF("%s", anchor.c_str());
00135 
00136     return (get_position(anchor) >= 0);
00137 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool images::ImagesDocument::is_open (  ) 

Check if the document has been opened.

Definition at line 69 of file images_document.cpp.

References LOGPRINTF.

00070 {
00071     LOGPRINTF("%d", images.size());
00072 
00073     return (images.size() > 0);
00074 }

bool images::ImagesDocument::open_document ( const std::string &  path,
bool  to_scan_dir = true 
)

Open .images index file.

Definition at line 52 of file images_document.cpp.

References images::BY_FILEPATH, LOGPRINTF, and images::ImagesScanner::scan_images().

Referenced by main().

00053 {
00054     using namespace images;
00055 
00056     ImagesScanner scanner;
00057 
00058     initial_page_num = scanner.scan_images(path,
00059                                            to_scan_dir,
00060                                            false,
00061                                            BY_FILEPATH, 
00062                                            true,
00063                                            images) + 1;
00064     LOGPRINTF("%d", initial_page_num);
00065 
00066     return true;
00067 }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int images::ImagesDocument::page_count (  ) 

How many "page" does it contain.

Definition at line 76 of file images_document.cpp.

References LOGPRINTF.

Referenced by main().

00077 {
00078     LOGPRINTF("%d", images.size());
00079 
00080     return static_cast<unsigned int>(images.size());
00081 }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208