Changeset 103


Ignore:
Timestamp:
Jun 8, 2009, 8:55:47 PM (5 years ago)
Author:
simon
Message:

map: make debug_level private, add load functions, code cleanup

Location:
branches/client-library-split
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/client-library-split/SConstruct

    r99 r103  
    4646] 
    4747 
    48 Default(env.Program('memphis', source = [SOURCES, 'main.c'])) 
     48Default(env.Program('memphis', source = ['main.c', SOURCES])) 
    4949 
    5050env.Program('testTextPath', source=['test/testTextPath.c','textpath.c']) 
     
    5555#env.Program('testRuleset', source=['ruleset.c','testRuleset.c']) 
    5656 
    57 env.Program('tile-renderer', source = [SOURCES, 'demos/tile-renderer.c']) 
     57env.Program('tile-renderer', source = ['demos/tile-renderer.c', SOURCES]) 
  • branches/client-library-split/demos/tile-renderer.c

    r101 r103  
    3333  gchar *path; 
    3434 
     35  map = memphis_map_new (); 
     36  memphis_map_load_from_file (map, "map.osm"); 
    3537  rules = memphis_rule_set_new (); 
    3638  memphis_rule_set_load_from_file (rules, "rule.xml"); 
    37    
    38   map = memphis_map_new_from_file ("map.osm"); 
    3939 
    4040  r = memphis_renderer_new_full (rules, map); 
  • branches/client-library-split/main.c

    r101 r103  
    171171 
    172172    ruleset = memphis_rule_set_new (); 
     173    osm = memphis_map_new (); 
     174 
     175    memphis_map_load_from_file (osm, opts->osmfn); 
     176    if (osm->map == NULL) 
     177        return(-1); 
    173178 
    174179    memphis_rule_set_load_from_file (ruleset, opts->cfgfn); 
    175     if(ruleset->ruleset == NULL) 
    176         return(-1); 
    177  
    178     osm = memphis_map_new_from_file (opts->osmfn); 
    179     if(osm->map == NULL) 
     180    if (ruleset->ruleset == NULL) 
    180181        return(-1); 
    181182 
  • branches/client-library-split/memphis-map.c

    r102 r103  
    3434 
    3535struct _MemphisMapPrivate { 
    36     int dummy; 
     36  gint8 debug_level; 
    3737}; 
    3838 
     
    4141                              GValue *value, GParamSpec *pspec) 
    4242{ 
    43   switch (property_id) { 
    44   default: 
    45     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 
     43  MemphisMap *self = MEMPHIS_MAP (object); 
     44  MemphisMapPrivate *priv = MEMPHIS_MAP_GET_PRIVATE (self); 
     45  switch (property_id) 
     46  { 
     47    case PROP_DEBUG_LEVEL: 
     48      g_value_set_int (value, priv->debug_level); 
     49      break; 
     50    default: 
     51      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 
    4652  } 
    4753} 
     
    5157                              const GValue *value, GParamSpec *pspec) 
    5258{ 
    53   switch (property_id) { 
    54   default: 
    55     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 
     59  MemphisMap *self = MEMPHIS_MAP (object); 
     60  switch (property_id) 
     61  { 
     62    case PROP_DEBUG_LEVEL: 
     63        memphis_map_set_debug_level (self, g_value_get_int (value)); 
     64        break; 
     65    default: 
     66      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);; 
    5667  } 
    5768} 
     
    6879  MemphisMap *self = MEMPHIS_MAP (object); 
    6980 
    70   osmFree(self->map); 
     81  if (self->map != NULL) 
     82    osmFree (self->map); 
    7183  G_OBJECT_CLASS (memphis_map_parent_class)->finalize (object); 
    7284} 
     
    105117memphis_map_init (MemphisMap *self) 
    106118{ 
     119  MemphisMapPrivate *priv = MEMPHIS_MAP_GET_PRIVATE (self); 
    107120  self->map = NULL; 
    108   self->debug_level = 1; 
     121  priv->debug_level = 1; 
    109122} 
    110123 
    111124MemphisMap* 
    112 memphis_map_new_from_file (gchar* filename) 
     125memphis_map_new () 
    113126{ 
    114   MemphisMap* mmap = g_object_new (MEMPHIS_TYPE_MAP, NULL); 
    115   mmap->map = osmRead(filename, mmap->debug_level); 
    116   return mmap; 
    117 } 
    118  
    119 MemphisMap* 
    120 memphis_map_new_from_data (gchar* data) 
    121 { 
    122   // TODO 
    123127  return g_object_new (MEMPHIS_TYPE_MAP, NULL); 
    124128} 
    125129 
    126130void 
    127 memphis_map_free (MemphisMap* map) 
     131memphis_map_load_from_file (MemphisMap *map, gchar *filename) 
     132{ 
     133  g_return_if_fail (MEMPHIS_IS_MAP (map)); 
     134 
     135  MemphisMapPrivate *priv = MEMPHIS_MAP_GET_PRIVATE (map); 
     136  if (map->map != NULL) 
     137    osmFree (map->map); 
     138 
     139  map->map = osmRead (filename, priv->debug_level); 
     140} 
     141 
     142void 
     143memphis_map_load_from_data (MemphisMap *map, gchar *data) 
     144{ 
     145  g_return_if_fail (MEMPHIS_IS_MAP (map)); 
     146 
     147  if (map->map != NULL) 
     148    osmFree (map->map); 
     149   
     150  // TODO 
     151  map->map = NULL; 
     152} 
     153 
     154void 
     155memphis_map_free (MemphisMap *map) 
    128156{ 
    129157  g_object_unref (G_OBJECT (map)); 
    130158} 
     159 
     160void 
     161memphis_map_set_debug_level (MemphisMap *map, 
     162    gint8 debug_level) 
     163{ 
     164  g_return_if_fail (MEMPHIS_IS_MAP (map)); 
     165 
     166  MemphisMapPrivate *priv = MEMPHIS_MAP_GET_PRIVATE (map); 
     167  priv->debug_level = debug_level; 
     168} 
     169 
     170gint8 
     171memphis_map_get_debug_level (MemphisMap *map) 
     172{ 
     173  g_return_val_if_fail (MEMPHIS_IS_MAP (map), -1); 
     174 
     175  MemphisMapPrivate *priv = MEMPHIS_MAP_GET_PRIVATE (map); 
     176  return priv->debug_level; 
     177} 
  • branches/client-library-split/memphis-map.h

    r90 r103  
    4646  GObject parent; 
    4747  osmFile *map; 
    48   gint8 debug_level; 
    49 /* 0: Be quiet 
    50    1: Normal Output (Default) 
    51    2: Be verbose */ 
    5248} MemphisMap; 
    5349 
     
    5854GType memphis_map_get_type (void); 
    5955 
    60 MemphisMap* memphis_map_new_from_file (gchar* filename); 
    61 MemphisMap* memphis_map_new_from_data (gchar* data); 
    62 void memphis_map_free (MemphisMap* map); 
     56MemphisMap* memphis_map_new (); 
     57void memphis_map_free (MemphisMap *map); 
     58 
     59void memphis_map_load_from_file (MemphisMap *map, gchar *filename); 
     60void memphis_map_load_from_data (MemphisMap *map, gchar *data); 
     61 
     62void memphis_map_set_debug_level (MemphisMap *map, gint8 debug_level); 
     63gint8 memphis_map_get_debug_level (MemphisMap *map); 
    6364 
    6465G_END_DECLS 
  • branches/client-library-split/memphis-renderer.c

    r102 r103  
    3636}; 
    3737 
     38typedef struct _MemphisRendererPrivate MemphisRendererPrivate; 
     39 
    3840struct _MemphisRendererPrivate 
    3941{ 
     
    5456memphis_renderer_new_full (MemphisRuleSet *rules, MemphisMap *map) 
    5557{ 
     58  g_return_val_if_fail (MEMPHIS_IS_RULESET (rules) && MEMPHIS_IS_MAP (map), NULL); 
     59 
    5660  MemphisRenderer* r = g_object_new (MEMPHIS_TYPE_RENDERER, NULL); 
    5761  memphis_renderer_set_map (r, map); 
     
    143147      && MEMPHIS_IS_MAP (priv->map)); 
    144148 
     149  g_return_if_fail (priv->map->map != NULL 
     150      && priv->rules->ruleset != NULL); 
     151 
    145152  info = g_new (renderInfo, 1); 
    146153  info->ruleset = ruleset = priv->rules->ruleset; 
     
    253260  priv->debug_level = debug_level; 
    254261  if (priv->map != NULL) 
    255     priv->map->debug_level = debug_level; 
     262    memphis_map_set_debug_level (priv->map, debug_level); 
    256263  if (priv->rules != NULL) 
    257264    memphis_rule_set_set_debug_level (priv->rules, debug_level); 
     
    448455  priv->zoom_level = 12; 
    449456  priv->debug_level = 1; 
    450    
    451457} 
    452458 
     
    454460memphis_renderer_get_row_count (MemphisRenderer *self) 
    455461{ 
     462  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
    456463  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    457464  return (1 << priv->zoom_level); 
     
    461468memphis_renderer_get_column_count (MemphisRenderer *self) 
    462469{ 
     470  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
    463471  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    464472  return (1 << priv->zoom_level); 
     
    468476memphis_renderer_get_min_x_tile (MemphisRenderer *self) 
    469477{ 
     478  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
    470479  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    471480   
     
    476485memphis_renderer_get_max_x_tile (MemphisRenderer *self) 
    477486{ 
    478   MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    479    
     487  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
     488  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
     489 
    480490  return lon2tilex (priv->map->map->maxlon, priv->zoom_level); 
    481491} 
     
    484494memphis_renderer_get_min_y_tile (MemphisRenderer *self) 
    485495{ 
     496  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
    486497  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    487498   
     
    492503memphis_renderer_get_max_y_tile (MemphisRenderer *self) 
    493504{ 
     505  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), -1); 
    494506  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self); 
    495507   
  • branches/client-library-split/memphis-renderer.h

    r97 r103  
    3838typedef struct _MemphisRenderer        MemphisRenderer; 
    3939typedef struct _MemphisRendererClass   MemphisRendererClass; 
    40 typedef struct _MemphisRendererPrivate MemphisRendererPrivate; 
    4140 
    4241struct _MemphisRenderer 
  • branches/client-library-split/memphis-rule-set.c

    r102 r103  
    141141memphis_rule_set_load_from_data (MemphisRuleSet *rules, gchar *data) 
    142142{ 
     143  g_return_if_fail (MEMPHIS_IS_RULESET (rules)); 
     144   
    143145  if (rules->ruleset != NULL) 
    144146    rulesetFree (rules->ruleset); 
     
    149151 
    150152void 
    151 memphis_rule_set_free (MemphisRuleSet* rules) 
     153memphis_rule_set_free (MemphisRuleSet *rules) 
    152154{ 
    153155  g_return_if_fail (MEMPHIS_IS_RULESET (rules)); 
     
    157159 
    158160void 
    159 memphis_rule_set_set_debug_level (MemphisRuleSet* rules, 
     161memphis_rule_set_set_debug_level (MemphisRuleSet *rules, 
    160162    gint8 debug_level) 
    161163{ 
     
    167169 
    168170gint8 
    169 memphis_rule_set_get_debug_level (MemphisRuleSet* rules) 
     171memphis_rule_set_get_debug_level (MemphisRuleSet *rules) 
    170172{ 
    171173  g_return_val_if_fail (MEMPHIS_IS_RULESET (rules), -1); 
  • branches/client-library-split/memphis-rule-set.h

    r101 r103  
    5555 
    5656MemphisRuleSet* memphis_rule_set_new (); 
    57 void memphis_rule_set_free (MemphisRuleSet* rules); 
     57void memphis_rule_set_free (MemphisRuleSet *rules); 
    5858 
    5959void memphis_rule_set_load_from_file (MemphisRuleSet *rules, 
     
    6262    gchar *data); 
    6363 
    64 void memphis_rule_set_set_debug_level (MemphisRuleSet* rules, 
     64void memphis_rule_set_set_debug_level (MemphisRuleSet *rules, 
    6565    gint8 debug_level); 
    6666 
    67 gint8 memphis_rule_set_get_debug_level (MemphisRuleSet* rules); 
     67gint8 memphis_rule_set_get_debug_level (MemphisRuleSet *rules); 
    6868 
    6969G_END_DECLS 
Note: See TracChangeset for help on using the changeset viewer.