]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blob - utilities.lisp
Break Protobufs support out into its own module with Quux.
[cl-protobufs.git] / utilities.lisp
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;                                                                  ;;;
3 ;;; Confidential and proprietary information of ITA Software, Inc.   ;;;
4 ;;;                                                                  ;;;
5 ;;; Copyright (c) 2012 ITA Software, Inc.  All rights reserved.      ;;;
6 ;;;                                                                  ;;;
7 ;;; Original author: Scott McKay                                     ;;;
8 ;;;                                                                  ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
11 (in-package "PROTO-IMPL")
12
13
14 ;;; Utilities
15
16 (defun proto-class-name (x)
17   (remove-if-not #'alphanumericp
18                  (camel-case (format nil "~A" x) :separators '(#\- #\_ #\/))))
19
20 (defun proto-field-name (x)
21   (remove-if-not #'alphanumericp
22                  (camel-case-but-one (format nil "~A" x) :separators '(#\- #\_ #\/ #\.))))
23
24 (defun proto-enum-name (x &optional prefix)
25   (let* ((x (string-upcase (string x)))
26          (x (if (and prefix (starts-with x prefix)) (subseq x (length prefix)) x)))
27     (remove-if-not #'(lambda (x) (or (alphanumericp x) (eql x #\_)))
28                    (format nil "~{~A~^_~}" (split-string x :separators '(#\- #\_ #\/ #\.))))))
29
30
31 #-quux
32 (progn
33
34 (defmacro i+ (&rest fixnums)
35   `(the fixnum (+ ,@(loop for n in fixnums collect `(the fixnum ,n)))))
36
37 (defmacro i- (number &rest fixnums)
38   `(the fixnum (- (the fixnum ,number) ,@(loop for n in fixnums collect `(the fixnum ,n)))))
39
40 (defmacro i= (&rest fixnums)
41   `(= ,@(loop for n in fixnums collect `(the fixnum ,n))))
42
43 (defmacro i< (&rest fixnums)
44   `(< ,@(loop for n in fixnums collect `(the fixnum ,n))))
45
46 (defmacro i> (&rest fixnums)
47   `(> ,@(loop for n in fixnums collect `(the fixnum ,n))))
48
49 (defmacro iash (value count)
50   `(the fixnum (ash (the fixnum ,value) (the fixnum ,count))))
51
52 (defmacro ilogior (&rest fixnums)
53   (if (cdr fixnums)
54     `(the fixnum (logior (the fixnum ,(car fixnums))
55                          ,(if (cddr fixnums)
56                             `(ilogior ,@(cdr fixnums))
57                             `(the fixnum ,(cadr fixnums)))))
58     `(the fixnum ,(car fixnums))))
59
60 (defmacro ilogand (&rest fixnums)
61   (if (cdr fixnums)
62     `(the fixnum (logand (the fixnum ,(car fixnums))
63                          ,(if (cddr fixnums)
64                             `(ilogand ,@(cdr fixnums))
65                             `(the fixnum ,(cadr fixnums)))))
66     `(the fixnum ,(car fixnums))))
67
68 (define-modify-macro iincf (&optional (delta 1)) i+)
69 (define-modify-macro idecf (&optional (delta 1)) i-)
70
71 )       ;#-quux