´ÙÀ½ ÀÌÀü Â÷·Ê

18. glib

glib´Â GDK ¹× GTK ¾îÇÃÀ» °³¹ßÇÒ ¶§ ¸¹Àº À¯¿ëÇÑ ÇÔ¼ö¿Í Á¤ÀǵéÀ» Á¦°øÇÑ´Ù. ³ª´Â ¿©±â¼­ ±×µéÀ» °£´ÜÇÑ ¼³¸í°ú ÇÔ²² º¸ÀÏ °ÍÀÌ´Ù. »ó´ç¼ö´Â Ç¥ÁØÀÇ libc¿Í Áߺ¹µÇ±â ¶§¹®¿¡ ±×µé¿¡ ´ëÇØ ÀÚ¼¼È÷ ´Ù·çÁø ¾Ê´Â´Ù. ÀÌ°ÍÀº ÁÖ·Î ÇϳªÀÇ Âü°í·Î¼­, ¾î¶² °ÍÀ» ÀÌ¿ëÇÒ ¼ö Àִ°¡¸¦ ÆľÇÇÏ°Ô ÇÒ °ÍÀÌ´Ù.

18.1 Á¤ÀÇ

¸¹Àº ÀÚ·áÇüµé¿¡ ´ëÇÑ extreme °ªµéÀÇ Á¤ÀÇ´Â ÀÌ·¸´Ù.

G_MINFLOAT
G_MAXFLOAT
G_MINDOUBLE
G_MAXDOUBLE
G_MINSHORT
G_MAXSHORT
G_MININT
G_MAXINT
G_MINLONG
G_MAXLONG

¶ÇÇÑ, typedefµéµµ ÀÖ´Ù. ¿ÞÂÊÀÇ °ÍµéÀº ±â°èÀÇ architecture¿¡ ÀÇÇØ ´Ù¸£°Ô ¼¼ÆõȴÙ. ȣȯ¼ºÀ» À¯ÁöÇÏ·Á¸é Æ÷ÀÎÅÍÀÇ Å©±â¸¦ Àç¾î¼­´Â ¾ÈµÈ´Ù´Â °ÍÀ» ¸í½É Ç϶ó. ÇϳªÀÇ Æ÷ÀÎÅÍ´Â Alpha ¿¡¼­ 8¹ÙÀÌÆ®, ÇÏÁö¸¸ Intel¿¡¼­´Â 4¹ÙÀÌÆ®ÀÌ´Ù.

char   gchar;
short  gshort;
long   glong;
int    gint;
char   gboolean;

unsigned char   guchar;
unsigned short  gushort;
unsigned long   gulong;
unsigned int    guint;

float   gfloat;
double  gdouble;
long double gldouble;

void* gpointer;

gint8
guint8
gint16
guint16
gint32
guint32

18.2 ÀÌÁß ¿¬°á ¸®½ºÆ®µé

¾Æ·¡ÀÇ ÇÔ¼öµéÀº ÀÌÁß ¿¬°á ¸®½ºÆ®µéÀ» ¸¸µé°í, °ü¸®ÇÏ°í, ¶Ç Æı«Çϱâ À§ÇØ ¾²ÀÌ´Â °ÍµéÀÌ´Ù. ÀÌ ¹®¼­¿¡¼­ ¿¬°á¸®½ºÆ®°¡ ¹«¾ùÀÎÁö ´Ù·ê ¼ø ¾ø±â¿¡, ³ª´Â ¿©·¯ºÐÀÌ ±×°ÍÀ» ÀÌ¹Ì ¾Ë°í ÀÖ´Ù°í °¡Á¤ÇÑ´Ù. ¹°·Ð, ±×°ÍÀº GTKÀÇ ÀϹÝÀûÀÎ ¾²ÀÓ»õ¸¦ ¾Ë±â À§ÇØ ²À ÇÊ¿äÇÑ °ÍÀº ¾Æ´ÏÁö¸¸, ±×·¡µµ ¾Ë¸é ÁÁÀº °ÍÀÌ´Ù.

GList* g_list_alloc       (void);

void   g_list_free        (GList     *list);

void   g_list_free_1      (GList     *list);

GList* g_list_append      (GList     *list,
                           gpointer   data);
                           
GList* g_list_prepend     (GList     *list,
                           gpointer   data);
                        
GList* g_list_insert      (GList     *list,
                           gpointer   data,
                           gint       position);

GList* g_list_remove      (GList     *list,
                           gpointer   data);
                           
GList* g_list_remove_link (GList     *list,
                           GList     *link);

GList* g_list_reverse     (GList     *list);

GList* g_list_nth         (GList     *list,
                           gint       n);
                           
GList* g_list_find        (GList     *list,
                           gpointer   data);

GList* g_list_last        (GList     *list);

GList* g_list_first       (GList     *list);

gint   g_list_length      (GList     *list);

void   g_list_foreach     (GList     *list,
                           GFunc      func,
                           gpointer   user_data);

18.3 ¿¬°á ¸®½ºÆ®

À§¿¡ ÀÖ´Â ¸¹Àº ÇÔ¼öµéÀº ´ÜÀÏ ¿¬°á¸®½ºÆ®µé¿¡ ´ëÇؼ­µµ ¾²ÀÏ ¼ö ÀÖ´Â °Íµé ÀÌ´Ù. ¿©±â ¿ÏÀüÇÑ ÇÔ¼öÀÇ ¸®½ºÆ®°¡ ÀÖ´Ù.

GSList* g_slist_alloc       (void);

void    g_slist_free        (GSList   *list);

void    g_slist_free_1      (GSList   *list);

GSList* g_slist_append      (GSList   *list,
                             gpointer  data);

GSList* g_slist_prepend     (GSList   *list,
                             gpointer  data);

GSList* g_slist_insert      (GSList   *list,
                             gpointer  data,
                             gint      position);

GSList* g_slist_remove      (GSList   *list,
                             gpointer  data);

GSList* g_slist_remove_link (GSList   *list,
                             GSList   *link);

GSList* g_slist_reverse     (GSList   *list);

GSList* g_slist_nth         (GSList   *list,
                             gint      n);

GSList* g_slist_find        (GSList   *list,
                             gpointer  data);

GSList* g_slist_last        (GSList   *list);

gint    g_slist_length      (GSList   *list);

void    g_slist_foreach     (GSList   *list,
                             GFunc     func,
                             gpointer  user_data);

18.4 ¸Þ¸ð¸® °ü¸®

gpointer g_malloc      (gulong    size);

ÀÌ°ÍÀº malloc()À» ´ëüÇÏ´Â °ÍÀÌ´Ù. ÀÌ ÇÔ¼öÀÇ ³»ºÎ¿¡¼­ ¸®ÅÏ°ª¿¡ ´ëÇÑ Ã¼Å©°¡ ÀÌ·ç¾îÁö¹Ç·Î ¿ì¸®°¡ µû·Î ±×°ÍÀ» ÇØÁÙ ÇÊ¿ä´Â ¾ø´Ù.

gpointer g_malloc0     (gulong    size);

À§¿Í °°Áö¸¸, ±×°ÍÀ» ÇâÇÑ Æ÷ÀÎÅ͸¦ ¸®ÅÏÇϱâ Àü±îÁø 0ÀÌ´Ù.

gpointer g_realloc     (gpointer  mem,
                        gulong    size);

"mem"¿¡¼­ ½ÃÀÛÇÏ¿© "size"¸¸Å­ÀÇ ¹ÙÀÌÆ®¸¦ ´Ù½Ã ÇÒ´çÇÑ´Ù. ¹°·Ð ±× ¸Þ¸ð¸®´Â ÀÌÀü¿¡ ÇÒ´çµÇ¾î ÀÖ¾î¾ß ÇÑ´Ù.

void     g_free        (gpointer  mem);

°£´ÜÇÏ´Ù, ¸Þ¸ð¸®¸¦ ¹Ý³³ÇÑ´Ù.

void     g_mem_profile (void);

»ç¿ëµÈ ¸Þ¸ð¸®ÀÇ profileÀ» ½ñ¾Æ³» ÁØ´Ù. ÇÏÁö¸¸ ÀÌ°ÍÀ» ¾²±â À§Çؼ± ¿ì¸®´Â glib/gmem.cÀÇ Á¦ÀÏ À­ºÎºÐ¿¡ #define MEM_PROFILEÀ» ´õÇØÁÖ°í make¸¦ ´Ù½Ã ÇØ¾ß ÇÑ´Ù.

void     g_mem_check   (gpointer  mem);

¸Þ¸ð¸®ÀÇ À§Ä¡°¡ À¯È¿ÇÑ °ÍÀÎÁö üũÇÑ´Ù. gmem.cÀÇ Á¦ÀÏ À­ºÎºÐ¿¡ #define MEM_CHECKÀ» ´õÇØÁÖ°í make¸¦ ´Ù½Ã ÇØ¾ß ÇÑ´Ù.

18.5 ŸÀ̸Ó

ŸÀÌ¸Ó ÇÔ¼öµéÀÌ´Ù.

GTimer* g_timer_new     (void);

void    g_timer_destroy (GTimer  *timer);

void    g_timer_start   (GTimer  *timer);

void    g_timer_stop    (GTimer  *timer);

void    g_timer_reset   (GTimer  *timer);

gdouble g_timer_elapsed (GTimer  *timer,
                         gulong  *microseconds);

18.6 ¹®ÀÚ¿­ ´Ù·ç±â

¹®ÀÚ¿­À» ´Ù·ç´Â ÇÔ¼öµéÀÌ´Ù. À̵éÀº ¸ðµÎ »ó´çÈ÷ Èï¹Ì·Ó°í, ¶ÇÇÑ Ç¥ÁØ C ¹®ÀÚ¿­ ÇÔ¼öµéº¸´Ù ´õ ¸¹Àº ±â´ÉµéÀÌ ÀÖÀ» °ÍÀÌ´Ù. ÇÏÁö¸¸ À̵鿡 ¹®¼­°¡ ÇÊ¿ä ÇÒ °ÍÀÌ´Ù.

GString* g_string_new       (gchar   *init);
void     g_string_free      (GString *string,
                             gint     free_segment);

GString* g_string_assign    (GString *lval,
                             gchar   *rval);

GString* g_string_truncate  (GString *string,
                             gint     len);

GString* g_string_append    (GString *string,
                             gchar   *val);

GString* g_string_append_c  (GString *string,
                             gchar    c);

GString* g_string_prepend   (GString *string,
                             gchar   *val);

GString* g_string_prepend_c (GString *string,
                             gchar    c);

void     g_string_sprintf   (GString *string,
                             gchar   *fmt,
                             ...);

void     g_string_sprintfa  (GString *string,
                             gchar   *fmt,
                             ...);

18.7 Utility ¿Í Error ÇÔ¼öµé

gchar* g_strdup    (const gchar *str);

strdupÇÔ¼ö¸¦ ´ëüÇÑ´Ù. ¿ø·¡ÀÇ ¹®ÀÚ¿­À» »õ·Ó°Ô ÇÒ´çµÈ ¸Þ¸ð¸®¿¡ º¹»çÇÏ°í, ±× °÷¿¡ ´ëÇÑ Æ÷ÀÎÅ͸¦ ¸®ÅÏÇÑ´Ù.

gchar* g_strerror  (gint errnum);

¸ðµç ¿¡·¯ ¸Þ½ÃÁö¿¡ ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇÒ °ÍÀ» ±ÇÇÑ´Ù. ÀÌ°ÍÀº perror()³ª ´Ù¸¥ °Íº¸´Ù ÈξÀ ¸ÚÁö°í, È®À强 ÁÁÀº °ÍÀÌ´Ù. Ãâ·ÂÀº º¸Åë ÀÌ·± Çü½ÄÀÌ´Ù.

program name:function that failed:file or further description:strerror

ÀÌ°ÍÀº ¿ì¸®ÀÇ hello_world ÇÁ·Î±×·¥¿¡ ¾²ÀÎ ¿¹Á¦ÀÌ´Ù.

g_print("hello_world:open:%s:%s\n", filename, g_strerror(errno));

void g_error   (gchar *format, ...);

¿¡·¯ ¸Þ½ÃÁö¸¦ Ãâ·ÂÇÑ´Ù. Çü½ÄÀº printf¿Í °°Áö¸¸, Ãâ·ÂÀÇ ¾Õ¸Ó¸®¿¡ "** ERROR **: "¸¦ ºÙÀÌ°í, ±×¸®°í ÇÁ·Î±×·¥À» ³¡³½´Ù. Ä¡¸íÀûÀÎ ¿¡·¯¿¡¸¸ »ç¿ëÇ϶ó.

void g_warning (gchar *format, ...);

À§¿Í °°´Ù, ÇÏÁö¸¸ "** WARNING **: "À» ¾Õ¸Ó¸®¿¡ ºÙÀÌ°í, ¶ÇÇÑ ÇÁ·Î±×·¥À» ³¡³»Áø ¾Ê´Â´Ù.

void g_message (gchar *format, ...);

¿ì¸®°¡ Ãâ·ÂÇÏ·Á´Â ¹®ÀÚ¿­¿¡ "message: "¸¦ ¾Õ¿¡¼­ ºÙ¿© Ãâ·ÂÇØÁØ´Ù.

void g_print   (gchar *format, ...);

printf¸¦ ´ëüÇÑ´Ù.

±×¸®°í ¿ì¸®ÀÇ ¸¶Áö¸· ÇÔ¼ö´Â ÀÌ°ÍÀÌ´Ù.

gchar* g_strsignal (gint signum);

ÀÎÀÚ·Î ÁØ ½Ã±×³Î ¹øÈ£¿¡ ÇØ´çÇÏ´Â À¯´Ð½º ½Ã½ºÅÛÀÇ ½Ã±×³Î À̸§À» Ãâ·ÂÇØÁØ´Ù. ´ë´Ù¼öÀÇ ½Ã±×³Î ´Ù·ç´Â ÇÔ¼öµé¿¡°Ô À¯¿ëÇÏ´Ù.

À§¿¡ ¼Ò°³µÈ ¸ðµç °ÍµéÀº glib.h¿¡¼­ ¸¶±¸ÀâÀÌ·Î ÀοëÇÑ °ÍÀÌ´Ù. ¿©·¯ºÐ Áß ´©±¸¶óµµ ¾î¶² ÇÔ¼ö¿¡ ´ëÇÑ ¹®¼­È­¸¦ ÇÏ°Ú´Ù¸é, ³ª¿¡°Ô emailÀ» º¸³»ÁÖ±æ!


´ÙÀ½ ÀÌÀü Â÷·Ê